How to add meta description in wordpress theme without plugin

How to add meta description in wordpress theme without plugin

SEO is the vital part of any website or blog. Most of the blogs unable to appear in Google first page due to lack of proper SEO.

Meta description tag is one of the most important tag for SEO. While anyone search with keywords Google submit the search results of that keywords with meta description tag below post title of the blog . Here is the best example of prioarena.com blog .While we search on Google with this keywords : Top ten best comedy drama in Eid ul adha 2019 we can see Google is showing our blog post in first place .

Again when we search prioarena.com we can see our sites meta description below the URL.

Here is our prioarena.com sites meta description is given how on the image below

 

So , you should apply it properly in your blog or website. Now you might asked me why do I used it without plugin ?

We have seen   plugin like yoast , seo plugin etc has the features of using meta description tag . Actually we know that using too many plugin can cause slow down the website so it can be very good idea to insert meta description tag directly using manual code.

Today I would like to show you how to use meta description tag in your WordPress theme without any plugin.

What is called meta description ?

A meta description (sometimes called a meta description attribute or tag) is an HTML element that describes and summarizes the contents of your page for the benefit of users and search engines.

So let’s get started ,

Step 1: Go to wp-content/themes folder, and browse the theme folder which currently being used.

Step 2: Find and open the file named functions.php.

Step 3: Add the following code to the functions.php file.

function gretathemes_meta_description() {
global $post;
if ( is_singular() ) {
$des_post = strip_tags( $post->post_content );
$des_post = strip_shortcodes( $post->post_content );
$des_post = str_replace( array("\n", "\r", "\t"), ' ', $des_post );
$des_post = mb_substr( $des_post, 0, 300, 'utf8' );
echo '<meta name="description" content="' . $des_post . '" />' . "\n";
}
if ( is_home() ) {
echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n";
}
if ( is_category() ) {
$des_cat = strip_tags(category_description());
echo '<meta name="description" content="' . $des_cat . '" />' . "\n";
}
}
add_action( 'wp_head', 'gretathemes_meta_description');

 

 

Step 4: Update the functions.php file in your theme by saving it. If you need to add meta keyword tag, add the code below to the functions.php file. Please note that the meta keyword tag is deprecated and not widely used by search engines. So use it with your consideration.

function gretathemes_meta_tags() {
echo '<meta name="meta_name" content="meta_value" />';
}
add_action('wp_head', 'gretathemes_meta_tags');

 

Please note, the above lines of code should be added before closing tags of php ?>

Additionally, if you plan to choose a new theme, please repeat the same steps in functions.php in your new theme.

So, you have finished adding meta tags to your WordPress website without plugins.

As you see, the process involves with custom coding a little bit. So, you might want to learn more about coding. It’s very interesting. Here is a list of some free places you can start with.

However, if coding is not your strength then a SEO plugin still helps. We highly recommended Slim SEO, a lightweight and automated SEO plugin for WordPress. You just need to install and activate it. There’s no configuration or options. Everything is done automatically.

 

How do you know you have successfully added meta description in your blog ?

Okay there are few great tools to test it but most quick and easy way to type your blog URL on Google search box and hit enter . If you have seen your blog name showing with extra other details below the title that means that are the meta description of your website and you have successfully added to your site.

Okay what if you never see any details of your blog in Google search options ?

The answer is you have added wrongly meta description tag. Or your meta description sucks. Don’t worry , we can fix it . Just add your problems below the comments section we will try our best to give you proper guidance and information to solve the issue.

 

Hopefully, this article will help you to make your site better. Good luck!

(Visited 68 times, 1 visits today)
Back to Top