Guest User

Google News Keywords, one category only

a guest
Dec 12th, 2012
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'wp_head', 'thsp_add_google_news_keyword_meta' );
  2. function thsp_add_google_news_keyword_meta() {
  3.  
  4.     global $post;
  5.    
  6.     if( is_single() && in_category( 'news-category' ) ) {
  7.        
  8.         $thsp_post_tags = wp_get_post_tags( $post->ID );
  9.             // Check if post has tags
  10.             if ( !empty( $thsp_post_tags ) ) {
  11.            
  12.             $thsp_tags_list = '';
  13.             foreach( $thsp_post_tags as $thsp_post_tag ) {
  14.                 $thsp_tags_list .= $thsp_post_tag->name . ', ';
  15.             }
  16.        
  17.             // Insert the meta tag, remove comma and space at the end
  18.             echo '<meta name="news_keywords" content="' . substr( $thsp_tags_list, 0, -2 ) . '">';
  19.         }
  20.     }
  21.    
  22. }
RAW Paste Data