WordPress.org

Ready to get started?Download WordPress

Forums

Next and Previous Links Add to #top to URL structure? (3 posts)

  1. blogthisnow
    Member
    Posted 1 year ago #

    On the next and previous links I want to add onto them.

    For example:

    <?php next_post( '%', 'Next', '' ) ?>

    Will output:

    <a href="http://mysite.com">Next</a>

    I want it to output

    <a href="http://mysite.com/#top">Next</a>

    Where are the core files to edit to enable me to hack this?

    Thanks

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    next_post() is deprecated - replace with http://codex.wordpress.org/Template_Tags/next_post_link

    try to use a filter function, added to fuctions.php of your theme;

    example:

    add_filter('next_post_link','add_anchor_to_adjacent_post_link');
    add_filter('previous_post_link','add_anchor_to_adjacent_post_link');
    function add_anchor_to_adjacent_post_link($link) {
    $link = str_replace('" rel','#top" rel',$link);
    return $link;
    }
  3. blogthisnow
    Member
    Posted 1 year ago #

    That worked perfect for adding anchors to next and previous links.

    Now my website visitors may stay longer.

    Good work.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic