Wordpress post meta description template

Unfortunately, not every SEO plugin has the functionality to write a post template, but with the help of this code, you can fix this problem a little. The code is added to the theme's header.php file before the closing </header> tag

<?php if (is_single() || (is_page())) { 
	$category = get_the_category(); ?>
	<meta name="description" content="Some text <?php echo get_the_title();?> text <?php echo $category[0]->cat_name; ?>. Some other text <?php $tags = get_the_tags(); if( $tags ){ foreach( $tags as $tag ){ echo $tag->name . ', '; } } ?> " >
<?php } ?>

In this case, we first check whether the opened page is a post or a page, and then we declare a variable to use the post category name in the description. using the clumsy get_the_tags construct, we can display all applied tags to a given entry in the description.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.