admin管理员组

文章数量:1297134

I want add WordPress post tags in meta property="article:tag".

Something like this:

This site is optimized with the Yoast WordPress SEO plugin v1.4.25
meta name="robots" content="noodp,noydir" 
meta name="robots" content="noodp,noydir"
meta name="description" content="Download last music" 
meta property="og:type" content="article" 
meta property="og:title" content="download new music"
meta property="article:tag" content="test2" 
meta property="article:tag" content="test3" 
meta property="article:tag" content="test4" 
meta property="article:section" content="download" 
meta property="article:section" content="download music" 
meta property="article:published_time" content="2014-03-11T21:42:57+00:00"
meta name="twitter:card" content="summary"
/ Yoast WordPress SEO plugin.

test2,test3,test4 are my post tags.

I want add WordPress post tags in meta property="article:tag".

Something like this:

This site is optimized with the Yoast WordPress SEO plugin v1.4.25
meta name="robots" content="noodp,noydir" 
meta name="robots" content="noodp,noydir"
meta name="description" content="Download last music" 
meta property="og:type" content="article" 
meta property="og:title" content="download new music"
meta property="article:tag" content="test2" 
meta property="article:tag" content="test3" 
meta property="article:tag" content="test4" 
meta property="article:section" content="download" 
meta property="article:section" content="download music" 
meta property="article:published_time" content="2014-03-11T21:42:57+00:00"
meta name="twitter:card" content="summary"
/ Yoast WordPress SEO plugin.

test2,test3,test4 are my post tags.

Share Improve this question edited Mar 13, 2014 at 17:18 Dan 8971 gold badge10 silver badges26 bronze badges asked Mar 13, 2014 at 16:36 alirezaalireza 1091 bronze badge 1
  • yes , but i can't do that. – alireza Commented Mar 13, 2014 at 19:58
Add a comment  | 

1 Answer 1

Reset to default 0

Since you are you using Yoast WordPress SEO plugin you can utilize its hook action wpseo_opengraph to add your custom meta tag property.

Add the following code to your theme functions.php file:

function wpse213_article_tag(){
    global $post;
    
    if($post->post_type == 'post') {    
        if($tags = get_the_tags($post->ID)) {
            foreach($tags as $tag) {
                echo '<meta property="article:tag" content="' . esc_attr($tag->name) . '" />' . "\n";
            }
        }
    }
}
add_action( 'wpseo_opengraph', 'wpse213_article_tag', 10 );

本文标签: How can I add meta tags in the WordPress header