How can I append NAMED ANCHOR to next_post_link()?

Discussion in 'WordPress' started by timothius, Aug 24, 2010.

  1. #1
    Hello everyone,

    I thought this would have been a commonly done thing, but I can't seem to find any information on how to do this.

    So on my single.php template, I have a link that goes to the next published post:

    <?php next_post_link('<p class="nextPostLink">%link</p>' ,'Next Post');?>
    Code (markup):
    Output:
    
    <a rel="next" href="http://localhost/wordpress/next-post-name.html">Next Post</a>
    HTML:
    At the end of the link I want to put a named anchor link at the end. So it would look like this:

    
    <a rel="next" href="http://localhost/wordpress/next-post-name.html#postBeginning">Next Post</a>
    HTML:
    Anyone know how I can do this? :confused:
     
    timothius, Aug 24, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Open link-template.php file from the directory wp-includes, find the function adjacent_post_link and change the line

    
    $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">';
    
    PHP:
    to

    
    $string = '<a href="'.get_permalink($post).'#postBeginning" rel="'.$rel.'">';
    
    PHP:
    But it will be affect all next and previous posts links.
     
    s_ruben, Aug 24, 2010 IP
  3. timothius

    timothius Active Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for that s_ruben!

    I'm trying to think... is there a reason I wouldn't want the named anchors on all next or previous post links?
     
    timothius, Aug 24, 2010 IP