I always asked myself why most WordPress theme don’t display any meta description. I created a short recipe to display a meta description, so read on and don’t hesitate to use it on your own theme!
I always asked myself why most WordPress theme don’t display any meta description. I created a short recipe to display a meta description, so read on and don’t hesitate to use it on your own theme!
Open your header.php file. Paste the following code anywhere within the <head> and </head> tags:
<?php if ( (is_home()) || (is_front_page()) ) { ?>
<meta name="description" content="Blog description goes here" />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php the_excerpt();?>"/>
<?php } ?>
Good job! Your theme now have meta description on the homepage as well as single posts. Also, we should create another conditionnal structure to handle categories.
Leave a Comment