How to Add Meta Tags in WordPress Without a Plugin

Meta tags help search engines understand your content and improve your website’s SEO, which is an important part of effective web design. If you don’t want to use a plugin, you can manually add meta tags to your WordPress theme files. Here’s how to do it.

Also n ote before you make any changes to php code make sure you make a backup.  Read our beginners guide to WordPress backups if this is an ara you are not comfortable withn.

Add Meta Tags in the Header.php File

Since meta tags belong in the <head> section of your site, you need to edit the header.php file.

Steps:

  1. Log in to WordPress and go to Appearance > Theme File Editor.
  2. In the right-hand panel, find and click on header.php.
  3. Look for the <head> section in the code.
  4. Add your meta tags before the closing </head> tag.

Example of Meta Tags:

<meta name="description" content="This is a short description of your website.">
<meta name="keywords" content="WordPress, SEO, Meta Tags, Website Optimization">
<meta name="author" content="Your Name">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
  1. Click Update File to save changes.

 

Add Meta Tags to Individual Pages and Posts

If you want to add custom meta tags to specific posts or pages, you can do it by editing the theme’s functions.php file.

Steps:

  1. Go to Appearance > Theme File Editor.
  2. Click on functions.php in the right panel.
  3. Scroll to the bottom and add this custom function:
function add_meta_tags() {
    if (is_single() || is_page()) {
        echo '<meta name="description" content="' . get_the_excerpt() . '">';
        echo '<meta name="keywords" content="custom, keywords, for, this, page">';
    }
}
add_action('wp_head', 'add_meta_tags');
  1. Click Update File to save changes.

This function will automatically add a meta description using the post excerpt and custom keywords for each individual page or post.

 

Add Meta Tags Using Custom Fields (For Individual Posts & Pages)

If you want more control over meta tags on specific pages, you can use custom fields.

Steps:

  1. Open the WordPress editor for any post or page.
  2. Scroll down and click Screen Options (top right).
  3. Check the box for Custom Fields.
  4. Scroll down and click Add Custom Field.
  5. In the Name field, enter meta_description or meta_keywords.
  6. In the Value field, enter your meta tag content, e.g., Best SEO tips for WordPress.
  7. Save the post/page.

Now, you need to tell WordPress to use this data in the <head> section.

 

Edit functions.php

  1. Open Appearance > Theme File Editor and click on functions.php.
  2. Add the following code:
function custom_meta_tags() {
    if (is_single() || is_page()) {
        $meta_description = get_post_meta(get_the_ID(), 'meta_description', true);
        if ($meta_description) {
            echo '<meta name="description" content="' . esc_attr($meta_description) . '">';
        }
    }
}
add_action('wp_head', 'custom_meta_tags');
  1. Click Update File.

This will dynamically add custom meta descriptions from the custom field you created.

Manually adding meta tags in WordPress without a plugin gives you full control over your site’s SEO. Whether you edit the header.php file, use functions.php, or take advantage of custom fields, these methods ensure search engines can properly index and rank your content.

Need help managing your WordPress site? Get expert WordPress support today!

Facebook
Twitter
LinkedIn
Pinterest

Table of Contents