functions - Add #primary at the end of navlink permalinks on single posts

I'm trying to add #primary at the end of the permalinks to the previous- and next post on all single post pages, to

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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742381710a4433249.html

相关推荐

  • functions - Add #primary at the end of navlink permalinks on single posts

    I'm trying to add #primary at the end of the permalinks to the previous- and next post on all single post pages, to

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信