I work a bit with the wordpress API and I want to try to include a <meta>-tag into my head area of my website.

This is my code (works everything fine!):

class dmd_noindex_options_page{
    function __construct() {
        add_action( 'wp_head', array( $this, 'set_meta') );
    function set_meta(){
       $pages = get_option('dmd_noindex_pages');
       $pages_id = explode(',', $pages);           
       for($i = 0; count($pages_id) > $i; $i++){
new dmd_noindex_options_page;

My problem:

I use the WP PlugIn Yoast SEO and if I take a look into my code of the website I see this above of my <meta>-tag.

<!-- This site is optimized with the Yoast SEO plugin v2.3.5 - https://yoast.com/wordpress/plugins/seo/ -->
<meta name="robots" content="noindex,follow"/>
<meta name="description" content="Impressum von EK Immobilien und Kontaktaufnahme"/>
<link rel="canonical" href="http://ek.dimadirekt.com/de/impressum/" />
<meta property="og:locale" content="de_DE" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Impressum -" />
<meta property="og:description" content="Impressum von EK Immobilien und Kontaktaufnahme" />
<meta property="og:url" content="http://ek.dimadirekt.com/de/impressum/" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:description" content="Impressum von EK Immobilien und Kontaktaufnahme"/>
<meta name="twitter:title" content="Impressum -"/>
<!-- / Yoast SEO plugin. -->

I don't want deactivate this Yoast SEO PlugIn! I tried to set a higher priority of my add_action but that doesn't work.


add_action( 'wp_head', array( $this, 'set_meta', 2,1) );

My question is:

How can I include my <meta>-tag above the <meta>-tags of the Yoast SEO Plugin? Can I include my code first of all plugins?

  • Are you trying to override the Yoast meta robots tag?
    – birgire
    Nov 10, 2015 at 12:24
  • Yes that is my goal.
    – cgee
    Nov 10, 2015 at 12:29

2 Answers 2


I just skimmed through the WPSEO_Frontend class and found the wpseo_robots filter for the meta robots content string.

You might try something like:

add_filter( 'wpseo_robots', function( $content )
        // your logic here ...
        return $content;    
} );

to override the robots meta content from that plugin.

ps: You should consider moving the add_action out of the class constructor.


Including it higher is probably not the right thing that you want as you are most likely to enter an "undefined functionality" on google side when encountering conflicting tags.

If you don't want the yoast SEO to output its tags you will need to find in its code how to disable or override the specific functionality.

But probably the most robust thing you can do is disallow those pages in robots.txt instead of "fighting" with all the SEO plugins. You can use the do_robotstxt action for that. something like (taken from here https://vip.wordpress.com/documentation/vip-development-tips-tricks/robots-txt/)

function my_disallow_directory() {
    echo "User-agent: *" . PHP_EOL;
    echo "Disallow: /path/to/your/directory/" . PHP_EOL;
add_action( 'do_robotstxt', 'my_disallow_directory' );
  • uuuh. A do_robotstxt hook? Never seen it before. I take a look into the documentation. Thank you.
    – cgee
    Nov 10, 2015 at 12:40
  • No great documentation for it but you can see it is used in the do_robots function developer.wordpress.org/reference/functions/do_robots/…. There is also a filter there so you have options.... Nov 10, 2015 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.