Skip to content
New: practical AI guides for website owners
Arsalan Masood Arsalan Masood
Guide · WordPress

How to Add Meta Tags to WordPress Without a Plugin

Short answer: To add meta tags to WordPress without a plugin, create a child theme and add a function to its functions.php that hooks into wp_head and prints the tag, escaped with esc_attr(). Store each post's description in a meta_description custom field, fall back to the excerpt, and never run this alongside an SEO plugin that prints the same tag.

Line drawing of two arrows in a loop beside the site's A, in midnight and blue
Key takeaways
  • Put the code in a child theme so theme updates don't delete it.
  • Hook a function into wp_head and escape the text with esc_attr().
  • A meta_description custom field gives each post its own description.
  • Google doesn't use the keywords meta tag; robots defaults to index, follow.
  • Never print a tag your SEO plugin already prints.

To add meta tags to WordPress without a plugin, put a small function in your child theme’s functions.php that hooks into wp_head and prints the tags, using a custom field so each post can have its own description. This guide gives you tested code for a meta description and a robots tag, shows how to fill the custom field in the block editor, and explains when you shouldn’t do this at all. The code was tested on a local WordPress install on 12 October 2026, and every function is documented on WordPress’s developer site.

Plugin or your own code? Your own code, this guide: a few tags with full control, no extra plugin, you maintain it. An SEO plugin, for most sites: titles, descriptions, schema and sitemaps, settings instead of code; never run both for the same tag.
One method per tag, or you’ll print duplicates.

Should you add meta tags without a plugin?

An SEO plugin is the easier choice for most sites: it handles titles, descriptions, social tags, schema and sitemaps from settings screens. Our Yoast SEO setup guide shows one. Writing your own code makes sense when you need only one or two tags, want to keep plugins to a minimum, or are building a custom theme.

The one rule: never output the same tag twice. If an SEO plugin already prints a meta description, adding your own creates a duplicate. When we tested this guide’s code on a site that already printed descriptions, the page ended up with two description tags. Pick one method per tag.

Which meta tags matter

Meta tags worth adding. Description for the search snippet: a short unique summary, sometimes shown by Google. Robots for indexing rules: noindex for thin pages; the default is index, follow. Skip these: keywords, which Google ignores, and viewport, which most themes add.
From Google’s list of supported meta tags.

Google’s list of supported meta tags includes:

  • description: “a short description of the page”, which Google says is sometimes used for the snippet in search results.
  • robots (and googlebot): rules for crawling and indexing. Google notes the default values are index and follow, so you only need the tag to change them, for example to noindex. If tags conflict, the more restrictive one applies.
Screenshot of Google's page on the meta tags it supports.
Screenshot Google’s list of supported meta tags, including description and robots. Captured October 12, 2026.

Google’s SEO Starter Guide also says Google Search doesn’t use the keywords meta tag, so there’s no need to add one. Your theme normally adds the viewport and character-set tags already, and WordPress itself prints the page <title> when a theme supports it.

Step 1: Use a child theme to add meta tags to WordPress without a plugin

WordPress’s theme handbook explains that a child theme extends a parent theme so you can customise it without editing the parent’s files, and still receive the parent’s updates without losing your changes. Code added to a parent theme’s functions.php disappears at the next update, so create a child theme first:

  1. In wp-content/themes/, create a folder such as mytheme-child.
  2. Add a style.css file whose header includes Theme Name and a Template line set to the parent theme’s folder name.
  3. Add an empty functions.php, then activate the child theme in Appearance → Themes.

Before editing any code, back up your site and make sure you can reach your files by SFTP or your host’s file manager. A typing mistake in functions.php can stop the site from loading, and you’ll need file access to undo it.

Adding meta tags without a plugin: create a child theme so updates keep your code, back up the site and keep FTP or file access, add a function on wp_head in the child theme's functions.php, fill a meta_description custom field per post, then check the page source for one correctly escaped tag.
Test on a staging copy first if you can.

Step 2: Add a meta description

Add this to your child theme’s functions.php. It runs on single posts and pages, uses a custom field called meta_description if you’ve filled it, and otherwise falls back to the first 30 words of the excerpt:

add_action( 'wp_head', 'mysite_meta_description', 1 );
function mysite_meta_description() {
	if ( ! is_singular() ) {
		return;
	}
	$post = get_queried_object();
	$desc = get_post_meta( $post->ID, 'meta_description', true );
	if ( '' === $desc ) {
		$desc = wp_trim_words( wp_strip_all_tags( get_the_excerpt( $post ) ), 30, '' );
	}
	if ( '' !== $desc ) {
		printf( '<meta name="description" content="%s">' . "\n", esc_attr( $desc ) );
	}
}

How it works, line by line:

  • add_action( 'wp_head', … ) runs the function inside the page’s <head>; WordPress’s documentation describes wp_head as the hook that prints scripts or data in the head, triggered by the theme.
  • is_singular() limits it to single posts and pages, so archives don’t all get the same description.
  • get_post_meta() reads your custom field; get_the_excerpt() provides the fallback.
  • esc_attr() makes the text safe inside an HTML attribute. In our test, a description containing quotes and a bold tag came out safely escaped, so it couldn’t break the page.

Step 3: Write each post’s description in a custom field

WordPress’s documentation explains how to show the Custom Fields panel in the block editor, which is hidden until used:

  1. Save your post first, because the next step reloads the page.
  2. Click the Options menu (three dots) at the top right, then Preferences.
  3. On the General tab, turn on Custom fields in the Advanced section, then click the button to reload the page.
  4. Below the editor, add a new field named meta_description with your description as the value, and update the post.

Write a short, unique summary of the page for each post, ideally one or two sentences, as Google’s guidance recommends.

Step 4: Keep thin pages out of search with a robots tag

Internal search result pages rarely deserve to appear in Google. This snippet, also tested, adds a noindex rule to them while still letting search engines follow their links:

add_action( 'wp_head', 'mysite_noindex_search', 1 );
function mysite_noindex_search() {
	if ( is_search() ) {
		echo '<meta name="robots" content="noindex, follow">' . "\n";
	}
}

Use noindex carefully: on the wrong page it removes that page from search. Never add it to posts and pages you want people to find, and check Settings → Reading to make sure “Discourage search engines from indexing this site” is off for the whole site.

Add a description for the home page

The snippet above covers single posts and pages. Your home page needs its own description too. This version uses the site tagline from Settings → General, so you can change it without touching code:

add_action( 'wp_head', 'mysite_home_description', 1 );
function mysite_home_description() {
	if ( ! is_front_page() ) {
		return;
	}
	$desc = get_bloginfo( 'description' );
	if ( '' !== $desc ) {
		printf( '<meta name="description" content="%s">' . "
", esc_attr( $desc ) );
	}
}

In our test it printed the tagline as the home page description. If your home page is a static page rather than your latest posts, the first snippet already covers it through is_singular(), so use one or the other to avoid two tags on the home page.

Why escaping matters

Descriptions come from text people type, and text can contain quotes, ampersands or angle brackets. Printed raw inside an HTML attribute, a single quote mark can end the attribute early and break the page’s head, or let unwanted code slip in. That’s why every snippet here wraps the text in esc_attr(), WordPress’s function for making text safe inside an attribute. Our test description deliberately included quotes and an HTML tag; the output showed them as harmless text. Keep the escaping in place whenever you adapt the code.

Step 5: Check the result

  1. Open a post, right-click and choose View Page Source.
  2. Search for name="description". You should see exactly one tag with your text.
  3. Check a search results page (yoursite.com/?s=test) for the robots tag.
  4. Use Search Console’s URL Inspection tool to see how Google reads the page.

Writing descriptions that earn clicks

The code only delivers what you write, so the description itself matters most. Google’s guidance asks for a short, unique description per page that includes the page’s most relevant points. In practice:

  • Say what the reader gets in plain words, in one or two sentences.
  • Include the main phrase people search for, once, naturally.
  • Keep every description different; copying the same text across posts gives Google nothing useful.
  • Front-load the important words, because long descriptions can be shortened in results.

Common problems

  • Two description tags: your theme or a plugin already outputs one. Remove your code, or turn off that feature in the plugin.
  • The site shows an error after saving functions.php: restore the previous file by SFTP or your host’s file manager, then fix the typing mistake.
  • No tag appears: check you edited the active child theme’s file and that the page is a single post or page.
  • Google shows different text: normal. Google mainly builds snippets from page content and uses your description when it fits the search better.
  • Your changes don’t show: a caching plugin or your host’s cache may still serve the old page. Clear the cache and check again in a private window.
  • The parent theme was updated and the code vanished: it was in the parent theme’s file. Move it to the child theme.

Moving to an SEO plugin later

If your needs grow, switching is simple. Install the plugin, then delete your functions from functions.php before turning on the plugin’s descriptions, so the two never run together. Your meta_description custom fields stay in the database; some SEO plugins can import custom fields, and if not, you can copy your most important descriptions across by hand. Check the page source again afterwards to confirm there’s one description per page.

Going further

The same approach works for other tags, such as Open Graph tags for social sharing, but each one is more code to maintain. If you find yourself adding several, an SEO plugin is usually the better tool. For everything else that helps a page rank, see our on-page SEO checklist and the WordPress SEO tutorial.

Questions people ask

Can I add a meta description in WordPress without a plugin?

Yes. Add a function to your child theme's functions.php that hooks into wp_head and prints the description from a custom field, escaped with esc_attr().

Where do I put the code?

In a child theme's functions.php, so updates to the parent theme don't remove it. Keep a backup and file access in case of a typing mistake.

Do I still need the keywords meta tag?

No. Google's SEO Starter Guide says Google Search doesn't use the keywords meta tag.

What if my SEO plugin already adds a description?

Then don't add your own; two description tags on one page conflict. Use one method per tag.

How do I show Custom Fields in the block editor?

Options (three dots) → Preferences → General → turn on Custom fields in Advanced, then reload the page.

How do I stop search results pages appearing in Google?

Print a robots meta tag with noindex, follow on search pages using is_search(), as shown in this guide.

Sources

  1. Meta tags that Google supports developers.google.com · checked October 12, 2026
  2. wp_head hook (WordPress developer reference) developer.wordpress.org · checked October 12, 2026
  3. Child themes (WordPress theme handbook) developer.wordpress.org · checked October 12, 2026
  4. Custom fields (WordPress.org documentation) wordpress.org · checked October 12, 2026
  5. SEO Starter Guide (Google) developers.google.com · checked October 12, 2026
Was this helpful?
Read nextThe full on-page SEO checklist
About the author Arsalan Masood

Building websites since 2006: 500+ web projects of every size and $300K+ in website deals sold or brokered. Founder of A Digital Motive and DigiFlippers. I share the whole process here, plainly.

Founder of A Digital Motive and DigiFlippers

Keep reading

More WordPress guides.

Scroll to Top