How To Add A Meta Description To Your WordPress Posts and Pages Without A Plugin

Meta descriptions are still relevant in search results. If you use any search engine, you read the meta descriptions in the results before deciding which one to click.

A meta description can be added to WordPress by creating a custom field. The text that is attributed to the field is read as the meta description. You don’t need a plugin to do this.

You see, when Google (or any other search engine) provides a snippet of the web page on the search results, they get that snippet from the page or post’s meta description, or from contextual information on the page such a bold text.

Using this page as an example, You’ll see that I give the vital information that the user may be looking for up front and centre, at the top of the article. It’s in bold. That text is also the text I use in the meta description field.

Create The Custom Field

First of all, click on the menu icon in the top right corner of the Gutenberg editor. It is the icon that has three vertical dots:

Head down to the item at the bottom – ‘Options’. In the pop up window, ensure you have ‘custom fields’ checked.

Now you should notice that at the bottom of your post, you can see a new section titled ‘Add New Custom Field:’

In the ‘Name’ drop down on the left, choose ‘description’. In the ‘Value’ field on the right, enter your meta description.

You’re not quite done yet. You now need to edit your functions.php file to display the meta description.

Edit functions.php To Display The Meta Description

Open functions.php and add the following code:

/*Display Custom Meta Descriptions */
function add_custom_meta_des(){

#Homepage Meta Description
if( is_home() || is_front_page() ){
	$meta_des = "Homepage meta description here"; #Edit here
	echo '<meta name="description" content="' . $meta_des . '" />';
}

#Single Page and Post Meta Description
if( is_single() || (is_page()){
	$des = get_post_meta( get_the_id(), 'description', true);
	if( ! empty( $des )  ){
		$meta_des = esc_html($des);
		echo '<meta name="description" content="' . $meta_des . '" />';
	}
}}
add_action( 'wp_head', 'add_custom_meta_des', 4 );

This will add the meta description to posts and pages. You can remove ‘|| (is_page()’ without the inverted commas if you just want to add the meta description to posts.

Also – don’t forget to add edit the above code to include your homepage description. You can edit this part of the code out if you don’t want to add a meta description to the homepage.

The following code will only add meta descriptions to posts, not pages or your homepage:

/*Display Custom Meta Descriptions */
function add_custom_meta_des(){

#Single Post Meta Description
if( is_single() ){
	$des = get_post_meta( get_the_id(), 'description', true);
	if( ! empty( $des )  ){
		$meta_des = esc_html($des);
		echo '<meta name="description" content="' . $meta_des . '" />';
	}
}}
add_action( 'wp_head', 'add_custom_meta_des', 4 );

You Don’t Need A Plugin

I hope you can see how easy this is to achieve in WordPress without using a plugin.

Very often we resort to bulky, unnecessary plugins to achieve simple tasks and very quickly end up with a WordPress installation bogged down with a load of junky plugins.

Very commonly ‘SEO plugins’ are used to achieve this task, but they really offer very little else in terms of functionality or added value for your site. I want to encourage you to deactivate and delete plugins like those and streamline your blog by carrying out simple tasks like this yourself.

Your site will load and display far quicker and you’ll be happier for it.