Is your website ranking poorly in the search engine results? Are you looking to improve the SEO of your website? Meta tags and description can boost your search engine rankings substantially.
In this article, we are going to show how you can add meta tag and meta description in your website with and without the help of plugins.
What is a meta tag and meta description?
Meta tags are elements that provide structured data about a webpage. These tags go inside the head section of a web page.
Meta description is a brief summary that gives a glimpse of the content in the page. It is visible in the search engine page below your website link.
Steps to add meta tags and meta description using a plugin
- Install and activate the All in One SEO plugin.
- Once the plugin is activated you will be redirected to a Setup Wizard. Click on the Let’s Get Started button.
- Scroll down to the Home Page Title section and add the title you would like for your website. Similarly under the Home Page Meta Description enter the description for the homepage of your website. Click on the Save and Continue button now.
- The title and meta description is done for the homepage now. You can skip the rest of the setting pages by clicking on the Save and Continue button till the wizard is complete.
- On the last page click on the Finish Setup and Go to the Dashboard button.
- The plugin allows you to add meta description and title for individual posts too. To add them follow the rest of the steps.
- Edit or create a new post.
- Scroll down to the AIOSEO Settings box. Under the Post Title option enter the title you want for the post. Similarly, under the Meta Description option enter the meta description for the post. You can add meta keywords under the Focus Keyphrase option. You can also view a live preview of how the post meta details will be visible in the search engine pages in Snippet Preview.
- Once done click on the Update button.
Steps to add meta tags and meta description without using a plugin
- From your admin dashboard navigate to Appearance -> Theme editor.
- Select the functions.php file from the Theme Files list.
- Add the below code to the file.
function add_meta_tags() { // Add meta tags to your homepage if (is_home()) { echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n"; } // Add meta tags to individual posts 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"; } // Add meta tags to your category pages if ( is_category() ) { $meta_description = strip_tags(category_description()); echo '<meta name="description" content="' . $meta_description . '" />' . "\n"; } } add_action( 'wp_head', 'add_meta_tags');
4. In the above code we have added the meta description for the homepage, category page and single posts. You can also add other meta tags such as the keyword tag by adding the below line of code in the sections of your website you want.
echo ‘<meta name=”keywords” content=”your, keywords, here”>’ . “\n”;
For example to add them in the categories page the code would become// Add meta tags to your category pages if ( is_category() ) { $meta_description = strip_tags(category_description()); echo '<meta name="description" content="' . $meta_description . '" />' . "\n"; echo '<meta name="keywords" content="your, keywords, here">' . "\n"; }
5. Once done click on the Update File button at the bottom and the meta tags and description will be added to your website.