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
.