Adding and optimizing a meta description in WordPress is a crucial step for enhancing your website’s SEO, as it’s often one of the first elements people see when searching online.
Meta descriptions provide a concise summary of your page content and appear below the page title in search engine results. By crafting compelling and relevant meta descriptions, you can attract more visitors to your site, increase click-through rates, and improve your site’s overall search engine ranking.
While a default WordPress installation doesn’t include a built-in feature for adding meta descriptions, this guide will show you how to add custom meta descriptions to your WordPress website without the need for any additional plugins
Adding Meta Description in WordPress
Step 1: Adding a Custom Field
To start adding a meta description, you’ll need a place to input them on your posts and pages. A custom field is an ideal choice for this.
WordPress has a built-in custom field feature, so you won’t need to install an additional plugin.
To enable it, open the WordPress default editor, click the three-dot icon in the top right corner, and go to the Preferences settings. Scroll down to the Advanced section and toggle on the Custom Fields option. Then, click the Enable & Reload button to save your settings.
Once you’ve activated the feature, a new Custom Fields panel will appear at the bottom of the editor.
You can now start adding meta descriptions to your posts and pages using this panel. Click the Enter New button to create a meta description custom field for the first time.
For the Name field, enter “meta-description”, and in the Value field, add the meta description for your post and pages.
For future posts and pages, you can simply select the `meta-description` custom field from the dropdown menu.
Save the post or page you’re editing, and then proceed to the next step.
If you’d like to display the custom field on your posts or pages, we have a separate article that covers how to do that.
Step 2: Integrate a Custom Code
The next step is to integrate a custom code to use the `meta-description` custom field as the post’s and page’s meta description. Here is the code for that:
function wpp_meta_description() { global $post; // Check if a custom meta description exists $custom_meta_description = get_post_meta( $post->ID, 'meta-description', true ); if ( ! empty( $custom_meta_description ) ) { $meta_description = $custom_meta_description; } if ( ! empty( $meta_description ) ) { echo '<meta name="description" content="' . esc_attr( $meta_description ) . '" />' . "\n"; } } add_action( 'wp_head', 'wpp_meta_description');
For safety and best practices, it’s recommended to add this code to the functions.php file of a child theme or by creating a custom plugin.
You can access the functions.php file by navigating to Appearance → Theme File Editor from your WordPress dashboard.
After adding the code, click the Update File button to apply the changes.
Step 3: Check for the Meta Description
By now, your post or page should have a meta description assigned to it within the <head>
section of its HTML.
To quickly verify this, you can inspect the HTML of the post from the front end. Right-click on the page and select Inspect from the menu, then search for “description” or a unique word in your meta-description value.
Now, when your page or post appears in search results, Google will use your meta description, as mentioned in their documentation.
The Bottom Line
In the guide, you learned how to add and optimize meta descriptions in WordPress, a crucial step for enhancing your website’s SEO. By crafting compelling and relevant meta descriptions, you improved your site’s click-through rates and search engine ranking.
Although WordPress doesn’t include a built-in feature for adding meta descriptions by default, this guide showed you how to create custom meta descriptions without the need for any additional plugins.