Site logo

Archived topic

How to use Noindex, Nofollow Metatags in Custom Template Page

3 replies · Started by Ashia on January 20, 2023

Viewing posts 1–4 of 4

Hello,
I am using a custom template, located in the GeneratePress Child theme folder. I am using this template for some specific posts using the Hook function, here are the codes I am using for the template, thanks to GeneratePress support for helping with making the template, https://generatepress.com/forums/topic/i-want-to-show-element-block-content-template-into-a-custom_template-php/#post-2492620

I want to use Noindex, and Nofollow meta tags for the template, or for the posts using this template. using robots.txt might help from not indexing, but I also want to make sure all links on the posts are nofollow.

Hi there,

you could include it in your Custom Template.
Change this:

get_header(); 
?>

to:

get_header(); 
add_action('wp_head', function(){echo '<meta name="robots" content="noindex">';});
?>

To cover, the get_header() function loads the themes header.php and that includes the wp_head hook.
So after the get_header() is called we can hook the meta tag into the wp_head

Thanks David

You're welcome

This archived topic is closed to new replies.