Meta description for every URL is soo important for SEO that you can imagine. It will be shown on SE results so here by adding your keywords and describing your full post in 150 characters can attract the visitor to click on your link out of thousands of result that SE give him to his query.
In WordPress, there are many plugins for SEO and every plugin have this option. They will ask you about meta description of your post while editing then will show it in your URL from where SE will pick it. But you better know that plugins can cause a heavy load on your hosting and also make your blog unsecure. So its time to leave using plugins for meta description in WordPress as we also hate WordPress plugins.
By using this code, your all meta description will be save into your database measn it will be secure if you remocved all plugins also. But if you will use plugins then after removing that plugin all of your meta description will be gone. So here below we have some codes that will pick your WordPress posts meta description text and will add automatically on every post page dynamically. It will also add meta description on Home Pages, Archive Pages, Search Pages, 404 Pages, Category Pages, Tags Pages so your every blog page will contain meta description tags.
Table of Contents
Features:
1.) Theme Function(function.php) file code.
2.) Header(header.php) file code also.
3.) Will give you a new space to add MetaDescription.
4.) Different MetaDescription for every post.
5.) No PLugin Required.
6.) Its a SEO Snippet.
7.) Light Weight code.
8.) Easy To Add.
9.) Every version of WordPress compatibility.
10.) Custom Field needed.
How To Add Dynamic Meta Description In WordPress Posts?
Step 1:) First of all, login to your WordPress blog and Add A New post or Edit anyone previous.
Step 2:) Make sure that you have enabled Custom Fields in your post editor dashboard.
Step 3:) Now go to Custom Fields below to the post editor dashboard and Enter new.
Step 4:) Here give a Name like something exe_meta_desc and put your post description text in Value column but keep in mind that it should be under 150 characters then click Add Custom Field.
Step 5:) Now you will see that your post description in Custom Fields is added. Now you can Delete and Update it also.
Step 6:) Now for another post, just edit/add post and follow Step 3 directly. BUt there you dont have to Enter new. Just open the dropdown menu –Select– and select exe_meta_desc from the lists. Now add your post description text in Value column but keep in mind that it should be under 150 characters then click Add Custom Field. Do it for every posts now.
How To Add Dynamic Meta Description In WordPress Theme?
Step 1:) Copy the below code and Paste in in your Theme Function(function.php) file.
/* ------------------------------------------------------------------------- * * Meta Description For SEO (Custom Field "exe_meta_desc") /* ------------------------------------------------------------------------- */ function seometadescription(){ global $post, $posts; if ( is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); $descriere = get_post_meta($post->ID, 'exe_meta_desc', true); endwhile; endif; elseif( is_category() ): $descriere = category_description(); elseif( is_front_page() ) : $descriere = 'Your Description Text For Non Post Pages.'; endif; $customMetaDesc = '<meta name="description" content="'.$descriere.'" />'; echo $customMetaDesc; }
Step 2:) Now Copy the below code and Paste in in your Header(header.php) file before </head>
tag.
<?php seometadescription(); ?>
Step 3:) Save and you are done.
Customization:
1.) Just change Your Description Text For Non Post Pages. with your default description text so except your WordPress posts pages, it will use the below tags like on Home Pages, Archive Pages, Search Pages, 404 Pages, Category Pages, Tags Pages so it mean you will be SEO rich without any plugin.
Theme Files Editing Warning:
Keep in mind that every code that you will add in your themes files will be removed when you will change the theme. So after changing your theme, you have to follow this article again and you will get everything back same as it is now.
Last Words:
This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.
Be the first to write a comment.