(+84) 463.28.7979

How to Insert META Description Tags in WordPress


It is essential to include the META Description tag on all your webpages for better search engine indexing. But most blog platforms and client do not create such unique description tags for each article page.

WordPress too does not create such META tags. META Description tags are inserted between the HEAD tags on the webpage. So how to create meta description tags for all your webpages which are customized for each page?

You need to edit the HEADER file in your blog template presentation. Then you need to add a META description tag.

It is easy to add meta description tag based on any custom text like
<meta name="description" content="any text you want">

or you can insert the blog description within the tags.
<meta name="description" content="<?php bloginfo('description'); ?>" >

or use this tag to get a short excerpt of your post into the description.
<meta name="description" content="<?php echo htmlentities(get_the_excerpt()); ?>" >

Now if you want to customize descriptions on specific pages like index page, single post pages, category pages or archives, you can place these codes between the conditional tags. “The Conditional Tags can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches.”

Some common conditional tags are
The Main Page
is_home()

A Single Post Page
is_single()

A PAGE Page
is_page()

A Category Page
is_category()

Any Archive Page
is_archive()

Not so complex? suppose you do not want to include the same blog description on all pages, but choose to include short post excerpts on all single post pages to make it more targeted. You get this code.
<?php if (is_single()) { ?>
<meta name="description" content="<?php echo htmlentities(get_the_excerpt()); ?>" />
<?php } ?>

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>