I'm trying to add #primary
at the end of the permalinks to the previous- and next post on all single post pages, to jump past the header directly to <div id="primary">
when going to the previous or next post.
Can anyone give me a hint on how to do this?
Sorry if the question is to basic for this forum. From what I can see in my searches, this question has not been posted in the forum before.
Eric
Update: I eventually managed to cut, paste and modify some code that seems to work. I've pasted the code below, since this forum should be a database for others looking for answers. If anyone with more experience than me have any suggestions for a better solution, please let us know! /Eric
/* Jump past header to div id #primary on single blog posts when clicking previous and next */
add_filter( 'next_post_link', 'add_div_id_to_navlink', 20, 5);
add_filter( 'previous_post_link', 'add_div_id_to_navlink', 20, 5);
function add_div_id_to_navlink( $output, $format, $link, $post, $adjacent )
{
if ( !$post )
return $output;
$title = $post->post_title;
$title = apply_filters( 'the_title', $title, $post->ID );
$permalink = get_permalink( $post );
$inlink = str_replace( '%title', $title, $link );
$inlink = str_replace( '%date', '', $inlink );
$inlink = '<a href="' . $permalink . '#primary">' . $inlink . '</a>';
$output = str_replace( '%link', $inlink, $format );
return $output;
}