最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Editing Category Pages

programmeradmin1浏览0评论

I want to allow Search engine Robots to index my category pages, But it seems noindex,follow tags is auto add by my theme functions

I want category pages to allow indexing while keeping noindex,follow for search and 404 pages

Here's is part of them (functions.php)

/*Add noindex to low value pages*/
function add_noindex_tags(){
    # Get page number for paginated archives.
    $paged = intval( get_query_var( 'paged' ) );

    # Add noindex tag to all archive, search and 404 pages.
    if( is_archive() || is_search() || is_404() )
    echo '<meta name="robots" content="noindex,follow">';

    # Add noindex tag to homepage paginated pages.  
    if(( is_home() || is_front_page() ) && $paged >= 2 )
    echo '<meta name="robots" content="noindex,follow">';
}
add_action('wp_head','add_noindex_tags', 4 );
?>

Can someone help me edit the code?

I want to allow Search engine Robots to index my category pages, But it seems noindex,follow tags is auto add by my theme functions

I want category pages to allow indexing while keeping noindex,follow for search and 404 pages

Here's is part of them (functions.php)

/*Add noindex to low value pages*/
function add_noindex_tags(){
    # Get page number for paginated archives.
    $paged = intval( get_query_var( 'paged' ) );

    # Add noindex tag to all archive, search and 404 pages.
    if( is_archive() || is_search() || is_404() )
    echo '<meta name="robots" content="noindex,follow">';

    # Add noindex tag to homepage paginated pages.  
    if(( is_home() || is_front_page() ) && $paged >= 2 )
    echo '<meta name="robots" content="noindex,follow">';
}
add_action('wp_head','add_noindex_tags', 4 );
?>

Can someone help me edit the code?

Share Improve this question asked Sep 25, 2019 at 12:39 kalkunkalkun 234 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

First, be sure to set up a child theme - don't edit the current theme unless it's a completely custom one. Otherwise, whenever you update your theme, your changes will be lost.

To do:

  • Check what folder your current theme is in. As an example, say you're using Twenty Nineteen - it's in a twentynineteen folder.

  • Create your own folder inside /wp-content/themes/. Perhaps /wp-content/themes/mychild/.

  • Create a style.css file inside that folder. It just needs two short comments:

/* Theme Name: My Child Theme Template: twentynineteen */

Note, you need to change the template (twentynineteen) to whatever your actual parent theme's folder is. That's it, you have a child theme. Go ahead and activate it, though it won't actually change anything yet.

  • Now create a functions.php file inside that same folder. Here, you're creating your own version of the function, and giving it a higher priority than the 4 that's used in your parent theme, so that yours will win out:
<?php
/*Add noindex to low value pages*/
function add_noindex_tags(){
    # Get page number for paginated archives.
    $paged = intval( get_query_var( 'paged' ) );

    # Add noindex tag to all archive, search and 404 pages.
    if( is_search() || is_404() )
    echo '<meta name="robots" content="noindex,follow">';

    # Add noindex tag to homepage paginated pages.  
    if(( is_home() || is_front_page() ) && $paged >= 2 )
    echo '<meta name="robots" content="noindex,follow">';
}
add_action('wp_head','add_noindex_tags', 5 );
?>

So, the two differences in your child theme's functions.php file are that you have removed is_archive() || from one condition (so the noindex tag will no longer be added to all archives, which includes your categories), and changed the priority on add_action() to 5.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论