admin管理员组

文章数量:1130349

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 ?

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 ?

本文标签: functionsAdd meta data in head from theme