首页 问答 正文

WordPress中最好的SEO插件是什么?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 121 次

WordPress中最好的SEO插件是Yoast SEO。

Yoast SEO可以帮助网站管理员进行关键词优化、页面标题和描述的设置、站内链接管理以及XML网站地图的生成等。

通过Yoast SEO,管理员可以快速优化自己的网站,使网站更符合搜索引擎的排名要求。

以下是一个设置Yoast SEO插件的示例代码:

//设置页面标题和描述
function my_page_title( $title ) {
    if ( is_home() || is_front_page() ) {
        $title = '网站首页 – 网站名称';
    } elseif ( is_category() ) {
        $title = single_cat_title( '', false ) . ' – ' . get_bloginfo( 'name' );
    } elseif ( is_archive() ) {
        $title = single_month_title( ' ', false ) . ' 归档 – ' . get_bloginfo( 'name' );
    } elseif ( is_search() ) {
        $title = '搜索结果: ' . get_search_query() . ' – ' . get_bloginfo( 'name' );
    }

    //设置默认页面描述
    $description = '这是我的网站,我会在这里分享一些我的想法。';
    if ( is_singular() ) {
        $post = get_post();
        $excerpt = $post->post_excerpt;
        //如果文章有设置摘要,则使用摘要做为描述
        if ( '' != $excerpt ) {
            $description = $excerpt;
        //如果文章没有设置摘要,则截取正文前150个字符作为描述
        } else {
            $description = mb_substr( strip_tags( $post->post_content ), 0, 150, 'utf-8' ) . '...';
        }
    }
    $description = htmlspecialchars( $description );
    echo '<meta name="description" content="' . $description . '">' . "n";

    //返回设置好的页面标题
    return $title;
}
add_filter( 'pre_get_document_title', 'my_page_title' ); 
大家谈论
    我的见解