3

I am trying to add the current post's author as the content for the meta author tag. I wrapped this particular meta in an is_single condition and then tried:

<meta name="author" content="<?php get_the_author(); ?>" />

as well as tried this:

<meta name="author" content="<?php the_author(); ?>" />

For both the above, Facebook debugger responded with:

Meta with name instead of property : The meta tag on the page was specified with name 'author', which matches a configured property of this object type. It will be ignored unless specified with the meta property attribute instead of the meta name attribute.


Then I tried:

<meta property="article:author" content="<?php the_author(); ?>" />

as well as tried this:

<meta property="article:author" content="<?php the_author(); ?>" />

For both the above, Facebook debugger responded with:

Parser Mismatched Metadata : The parser's result for this metadata did not match the input metadata. Likely, this was caused by the data being ordered in an unexpected way, multiple values being given for a property only expecting a single value, or property values for a given property being mismatched. Here are the input properties that were not seen in the parsed result: 'article:author'.


What am I doing wrong as all of the above four metas just return a blank content (<meta name="author" content/>) for the author tag.

  • Is your code inside the Loop? – coopersita Sep 26 '15 at 19:02
  • @coopersita The meta tag? It's in the <head>....</head> section so I think it's not within the loop. – AndrewL64 Sep 26 '15 at 19:19
  • According to the documentation, the_author must be in the loop. – coopersita Sep 26 '15 at 19:24
  • But how can I include a <meta> tag in the body section? – AndrewL64 Sep 26 '15 at 19:47
2

You cad add it via functions.php with a hook, instead of inside the loop (you don't really want to add a loop to header.php):

function add_author_meta() {

    if (is_single()){
        global $post;
        $author = get_the_author_meta('user_nicename', $post->post_author);
        echo "<meta name=\"author\" content=\"$author\">";
    }
}
add_action( 'wp_enqueue_scripts', 'add_author_meta' );
  • I added the above to my functions.php file but the meta tag is not being echoed unfortunately :( – AndrewL64 Sep 27 '15 at 7:06
  • It will only work on single pages. Does your theme have wp_head() in header.php? – coopersita Sep 27 '15 at 15:08
0

Add this into header.php

<meta name="author" content="<?php the_author_meta('user_nicename', $post->post_author); ?>">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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