This is feature image

How To Add Meta Tags In WordPress Without Plugin

Published by on August 11, 2023
Categories: BLOG WORDPRESS

In this article, we will explain the step-by-step method:  To add meta tags in WordPress without plugin. In this method, meta tags will be generated uniquely for each post page according to the article. As we know that WordPress does not contain keywords and description meta tag data in the default installation.  In this article, we will explain How To Add Meta Tags In WordPress Without Plugin.

what are Meta tags?

HTML Meta tags are used to provide information about data on web pages to search engines. HTML meta tags are written inside the head section of the HTML page. We can not see Meta tags on the web page, they reside in source code and provide information to search engines about the page.

Meta Tags SEO Importance

Meta Tags SEO is very important for our website or blog to get more traffic. The main meta tags important for SEO are meta description and meta keywords. Meta description helps to describe our content on SERPs. Visitors read Meta’s description and click our page link. Meta description helps to increase our CTR. Meta Keywords also meta tags which include some tags about our page. Meta Keywords helps search engines to understand our content.

How HTML Meta Tags Description Improve Web Traffic.

When a user searches on google, google lists about 10 organic results per page. Some pages may have fewer results. In the search result, google display the title and description of the post page. So if the meta tags description is to the point and expresses a solution for the viewer’s problem, it will increase the chance that the viewer will click the link of the post or article. So meta description is very important to impress the viewer to click your website or blog post link. Now it is clear meta tag descriptions are important to improve SEO indirectly.

Best Methods to Add the Meta Tag Description to WordPress.

Meta tag can be added manually, by adding code to the Theme template files, or through WordPress Plugins.

Adding meta tag descriptions manually or using code to generate meta tag reduce the number of plugins in your WordPress blog, as a result, it improves WordPress speed. It also provides flexibility to add meta tags. But adding meta tag descriptions for each page, for a large site is a very tedious job.

So here we will show you a method to generate unique meta tag descriptions automatically for each post, using code in your WordPress blog . 

How does this code generate a unique meta tag description for each post?

This code will automatically generate meta tag descriptions from your first paragraph of the post. The paragraph’s first 160 words are taken into account.

Google search results display a description that is approximately 150 to 160 words. It’s important to provide concise information that explains the article’s purpose in the first 150 to 200 words. Write in such a way that grabs the viewer’s attention.

By doing so, you can attract viewers to click on your link and increase your CTR.

Steps: How To Add Meta Tags In WordPress Without Plugin

If you do not know the technicalities of WordPress themes don’t worry just follow the steps. It is an easy guide to add code for meta tag description.

1. Accessing the Theme Files Editor in WordPress Dashboard.

In the left sidebar search for appearance and hover on it and then click “Theme File Editor”, steps are mentioned in the image below.

First step Screenshot of the Appearance in Dashboard  How To Add Meta Tags In WordPress Without Plugin

2. Locating the Header.php File and Inserting code for Meta Tags

Now find the header.php file in the right sidebar under the Theme Files title. Now you will see code in the editor in the dashboard’s center. Insert new code, between section, new code is highlighted, as shown in the image below.

How To Add Meta Tags In WordPress Without Plugin

Copy the following code and insert in header.php

<?php
	if ( is_singular() ) {
	    $post_des = strip_tags( $post->post_content );
	    $post_des = strip_shortcodes( $post->post_content );
	    $post_des = str_replace( array("\n", "\r", "\t","<p>","</p>","<strong>","</strong>","&nbsp;","<!-- wp:paragraph -->","<!-- /wp:paragraph -->","  "), ' ', $post_des );
		
        $post_des = mb_substr( $post_des, 0, 220, 'utf8' );
		echo '<meta name="description" content="' . $post_des . '" />' . "\n";
    }
    if ( is_home() ) {
        echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n";
    }
    if ( is_category() ) {
        $cat_des = strip_tags(category_description());
        echo '<meta name="description" content="' . $cat_des . '" />' . "\n";
    }
	?>

Now click “Update File”. Don’t forget to update the file, otherwise, the change will be lost.

Conclusion

Meta tag description is very important in search engine result pages. It helps a lot to improve the CTR of the WordPress blog page. In this article, we have explained, how to add code in WordPress to generate meta tag descriptions automatically.

Related Posts

Gurjit

Gurjit Singh is a Content Writer and Web developer. He has experience in theme development, front-end development, and digital market. He loves to share his knowledge to help others in creating Websites, WordPress blogs, and SEO.