• Hi,

    Is there any way or any tags that can return the ‘raw’ link to previous/next posts? eg. https://mysite.com/post/

    Have tried various tags, but they all return .

    Am trying to put the previous/next post link in javascript.

Viewing 4 replies - 1 through 4 (of 4 total)
  • get_previous_post() and get_next_post() are defined in wp-includes/template-functions-links.php.

    You could use these functions, and also review previous_post_link() and next_post_link() (both of which echo instead of return) for how to obtain the links you need.

    Thread Starter tyh

    (@tyh)

    Want to put the link in the code location.href=(link)

    Using get_previous_post() gives
    location.href=('')

    while using previous_post_link() gives
    location.href=('&laquo; <a href="https://mysite.com/link">Post title</a>')

    Have tried putting ‘echo get_previous_post()’ which gives location.href=('Object')

    Any ideas?

    n.b. In above post,
    Have tried various tags, but they all return .

    should be
    Have tried various tags, but they all return <a href="https://mysite.com/link"></a>.

    get_previous_post() returns an actual post object. With this object, you could then feed the previous post’s ID to get_permalink().

    Also take a look at the arguments accepted by previous_post_link() and next_post_link() for ways to control and format the link.

    Check out these wp-codex pages, you might find a solution for what you want to do:
    https://codex.www.ads-software.com/Template_Tags/previous_post
    https://codex.www.ads-software.com/Template_Tags/next_post

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘‘Raw’ link to previous/next post’ is closed to new replies.