The title tag and meta description summarize the main idea of a web page and are displayed in the SERPs.
By default, WordPress correctly puts the title tag on all pages, but for meta description you need to put it manually. In this tutorial you will learn how to add meta description in WordPress pages and posts.
Add meta description in WordPress without plugin
Meta descriptions are often referred to as SEO descriptions. They are placed in the meta tag and are always placed in the head element of the page’s HTML code.
Here is how it looks in the code:
<meta name="description" content="Your description 🥰">
Step 1.Add below code snippet to functions.php
In the WordPress dashboard, go to Appearance ➡ Theme File Editor and copy the following code into the theme’s functions.php file and update it.
You must create a child theme before making any changes to functions.php
file. Otherwise, the applied changes will be lost after each update.
Create child theme in WordPress step by step [without plugin]
As an alternative method, you can use the Code Snippets plugin to insert your codes into WordPress.
function meta_description_r(){
if( is_single() || is_page() ) { ?>
<meta name="description" content="<?= wp_strip_all_tags( get_the_excerpt(), true ); ?>">
<?php } }
add_action('wp_head', 'meta_description_r');
The above code gets the excerpt of the article as meta description and puts it in the head of page.
Step 2.Write an excerpt for your articles
Go through each of your articles and write an excerpt for them.
If your article excerpt is empty, this code will put the first 600 characters of the article in the meta description.
Now, if you check the source of your blog posts, you will notice that the meta description has been added to the head of the page.
If this article is difficult for you to read in text, you can watch the video version below.
That’s it, If you have a question, be sure to comment for us to answer.
great