banner



How To Add Meta Tags In Wordpress Blog Post

Read Time: 5 mins Languages:

In this tutorial, I'll show you how to add meta tags to your WordPress website. By default, WordPress doesn't support meta tags, but with a few easy steps you can add support for meta tags in your WordPress website.

Meta tags are important when it comes to making your website SEO-friendly. When search engine crawlers visit your website, they fetch metadata information in the form of meta tags in addition to fetching the actual content of that page. In fact, meta tags allow us to inform crawlers about the specifics of the web pages.

There are certain keyword meta tags that don't contribute to the search engine ranking of your website, although some meta tags like meta description can significantly improve search results.

WordPress doesn't come with built-in support for meta tags, so you need to do a bit of extra work if you want to take advantage of meta tags. Broadly speaking, when it comes to providing meta tags support in WordPress, there are two ways: either you need to edit the WordPress code files or you need to install a third-party plugin. In this article, we'll discuss both ways.

How to Add Meta Tags to WordPress Without a Plugin

In this section, we'll discuss how you could enable meta tags support in your WordPress website without any plugins.

To enable meta tags support, we'll have to add a code snippet in the functions.php file of your active theme. If you're using your own custom theme, you can edit the functions.php file directly. However, if you're using a third-party theme like Twenty Twenty, you should create a child theme before you make any changes.

You can learn how to create a child theme here:

In this example, I'll show you the code for a Twenty Twenty child theme. Go ahead and open the wp-content/themes/{YOUR_THEME}/functions.php file and add the following snippet at the end.

function twentytwenty_add_meta_tags() { // homepage if (is_home()) { echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n"; } // single post page if ( is_singular() ) { global $post; $meta_description = strip_tags($post->post_content); $meta_description = strip_shortcodes($post->post_content); $meta_description = str_replace(array("\n", "\r", "\t"), ' ', $meta_description); $meta_description = substr($meta_description, 0, 160); echo '<meta name="description" content="' . $meta_description . '" />' . "\n"; } // category page if ( is_category() ) { $meta_description = strip_tags(category_description()); echo '<meta name="description" content="' . $meta_description . '" />' . "\n"; } } add_action( 'wp_head', 'twentytwenty_add_meta_tags');        

In the above snippet, we've added the twentytwenty_add_meta_tags custom function, which will add meta tags to the different pages of your website. We've then used the wp_head hook to add meta tags to your pages. Of course, if you're using a different theme, replace twentytwenty_add_meta_tags with the name of your own theme.

As you can see, we've implemented meta tags support for the home page, single post page, and category pages. Of course, you could go ahead and modify this code as per your needs. You could add support for other types of pages similarly.

In the next section, we'll see how you could add meta tags by using third-party plugins.

How to Add Meta Tags With Third-Party Plugins

In this section, we'll see how to add meta tags to your website with the help of the Meta Tag Manager plugin. You can install it with from the WordPress admin sidebar with Plugins > Add New, or you can download and install it manually to your wp-content/plugins directory.

Finally, activate the plugin in the Plugins section of the admin sidebar.

Once the plugin is installed, you can access the plugin UI at Settings > Meta Tag Manager.

Meta Tag Manager UI Meta Tag Manager UI Meta Tag Manager UI

There are two ways you could use this plugin. You can add custom meta tags for specific pages or you could enable meta tags for specific content types like post, page, and media. So it depends on how you would like to configure meta tags in your website.

How to Add the Meta Description Tag for the Front Page

In this section, we'll see how you could add the meta description tag only on the homepage. Head over to the Settings > Meta Tag Manager > Custom Meta Tags section, click on the + Add Meta Tag button, and configure the meta description tag as shown in the following screenshot.

Frontpage Meta Description Tag Frontpage Meta Description Tag Frontpage Meta Description Tag

Click on the Save Changes button to save your changes.

Meta Tags Listing Meta Tags Listing Meta Tags Listing

Go ahead and check the source code of your front page (Control-U in Chrome), and you will see the following meta tag added by the Meta Tag Manager plugin!

<meta name="description" content="Just another WordPress site" />        

In this way, you can add as many tags as you want to add to your pages.

How to Enable the Meta Tag Builder for the Post Content Type

The other option is to enable the meta tag builder for specific content types. For example, if you want to enable the meta tag builder for the Post content type, go to the Settings > Meta Tag Manager > General Options section. Select the Posts content type, as shown in the following screenshot, and hit the Save Changes button to save changes.

General Options General Options General Options

Now, go ahead and create a new post, and you'll notice that the meta tag builder is added to it, as shown in the following screenshot.

Post Content Type Post Content Type Post Content Type

You would use it in the same way as we discussed in the previous section. In this way, you can enable the meta tag builder for different content types.

Conclusion

Today, we discussed different ways in which you can enable meta tags support in your WordPress website.

If you want to learn how to make a WordPress site from A to Z, be sure to check out our complete guide.

You can also learn how to use WordPress with our free online course.

Sajal Soni

Software Engineer, FSPL, India

I'm a software engineer by profession and I've done my engineering in computer science. It's been around 14 years I've been working in the field of website development and open source technologies. Primarily, I work on PHP and MySQL based projects and frameworks. Among them, I've worked on web frameworks like CodeIgnitor, Symfony, and Laravel. Apart from that, I've also got a chance to work on different CMS systems like Joomla, Drupal and WordPress, and e-commerce systems like Magento, OpenCart, WooCommerce and Drupal Commerce. I also like to attend community tech conferences, and as a part of that, I attended 2016 Joomla World Conference held in Bangalore (India) and 2018 DrupalCon which was held in Mumbai (India). Apart from this, I like to travel to explore new places and listen music!

How To Add Meta Tags In Wordpress Blog Post

Source: https://webdesign.tutsplus.com/tutorials/how-to-add-meta-tags-in-wordpress--cms-36254

Posted by: vasquezsomforeatty.blogspot.com

0 Response to "How To Add Meta Tags In Wordpress Blog Post"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel