functions - Add meta data in head from theme

admin2025-06-07  15

I want to add a meta data in the head of my website.

I have a post type with custom template : single-custom.php

In this template, I want to add this meta : <meta name="robots" content="noindex"> considering some variable.

I collect number of post related to the current post... I use :

// if less than 6 related posts, add meta
if (count($posts) < 6) {
      add_action( 'wp_head', 'noindex_meta' );
}

And in my functions.php :

// add noindex meta to head
function noindex_meta() {
    echo '<meta name="robots" content="noindex">';
}

But it doesn't work, it works if I call add_action(...) in my functions.php, but not in theme template.

Is it possible ?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749229970a317452.html

最新回复(0)