1

Struggling with this one...

In my WordPress theme I have a gallery at the top and blog posts below it. Each time I click the previous or next posts links it goes to the top which I don't want so I have created an anchor called #blog and placed in my html just below the gallery. How do add the anchor to the previous_post_links and next_posts_links to make it work? Is there a JavaScript solution for this?

Emily Harris
  • 147
  • 2
  • 14

3 Answers3

1

I know this is an old question, but here is how I dealt with adding an anchor to the previous and next posts link. You would add this into functions.php between the opening and closing tags.

add_filter('get_pagenum_link', 'whatever_next_previous_anchor');

function whatever_next_previous_anchor($url) {
    return $url . '#blog';
}
zachzurn
  • 2,111
  • 13
  • 26
0

Do the next and previous links have an ID or class that identifies them? Even if they don't you can still use Javascript or Jquery to append the #blog anchor to each link value. Check out this link Adding a parameter to the URL with JavaScript.

Community
  • 1
  • 1
thestepafter
  • 578
  • 1
  • 4
  • 19
0

I think that should do it, by using get_previous_post() instead :

     $prev_post = get_previous_post();
     if (!empty( $prev_post )): ?>
      <a href="<?php echo get_permalink( $prev_post->ID ); ?>#blog">
        <?php echo $prev_post->post_title; ?></a>
     <?php endif; ?>
Jean
  • 701
  • 5
  • 11