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 get_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.

3 Answers
3

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' );

Leave a Reply

Your email address will not be published. Required fields are marked *