How to add a meta description in WordPress without a plugin
WordPress does not print a meta description. To add one without a plugin, hook a function to wp_head that outputs <meta name="description"> using the post's excerpt, with fallbacks: trimmed content when there is no excerpt, the term description on category and tag archives, and the tagline on the homepage.
This gives you a field you already have, the Excerpt box, as the place to write each description. It suits small sites and developers who want to keep the plugin count down.
Step by step
1. Add the snippet
Put this in your child theme's functions.php or a small plugin:
add_action( 'wp_head', function () {
$text = '';
if ( is_front_page() ) {
$text = get_bloginfo( 'description' );
} elseif ( is_singular() ) {
$post = get_queried_object();
$text = has_excerpt( $post )
? get_the_excerpt( $post )
: wp_trim_words( strip_shortcodes( $post->post_content ), 28, '' );
} elseif ( is_category() || is_tag() || is_tax() ) {
$text = term_description();
}
$text = trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( $text ) ) );
if ( '' !== $text ) {
printf( '<meta name="description" content="%s" />' . "\n", esc_attr( $text ) );
}
}, 5 );
wp_strip_all_tags() removes HTML and block comments, and esc_attr() makes the text safe inside the attribute. Pages with no text to offer, such as search results, get no tag, which is better than an empty one.
2. Write descriptions in the Excerpt field
For each post, open the editor's settings sidebar and fill in Excerpt with one or two sentences that answer the search the post targets. Whatever you write there becomes the description. Without an excerpt the snippet falls back to the first 28 words of the content, which is acceptable but rarely the best summary.
3. Enable excerpts on pages
Pages have no Excerpt field by default. Add support so you can write descriptions for them too:
add_action( 'init', function () {
add_post_type_support( 'page', 'excerpt' );
} );
Reload the page editor and the field appears.
4. Describe categories and tags
The archive branch uses the term's Description, edited under Posts → Categories or Posts → Tags. Write one for each archive you want in search. Some themes also display this text at the top of the archive, so write it for readers, not as a keyword list.
5. Mind the length
Google does not have a fixed character limit. It truncates snippets by pixel width, which works out near 155 to 160 characters on desktop and less on mobile. Write the important part in the first 120 characters. Do not truncate in code: a description cut mid-sentence by your function is worse than one Google shortens itself.
6. Check the output
curl -s https://example.com/a-post/ | grep -i '<meta name="description"'
Check a post with an excerpt, a post without, a category and the homepage. There must be exactly one description tag on each. Two usually means the theme prints its own, which a few themes do. Remove one of them.
7. Know when you have outgrown it
This snippet covers one tag. It has no preview, no per-page override separate from the excerpt, no social tags, no canonical or noindex control and no structured data. If you find yourself adding snippets for each of those, a plugin is less code to maintain. When you install one, delete this snippet first, or pages will print two descriptions.
The excerpt has other jobs
Themes often show the excerpt on blog index and archive pages, and feeds use it when set to show summaries. Using it as the meta description means the same sentence appears in those places. Usually that is fine, since a good summary works in all three. If you need different text for search, you need a separate custom field and a few more lines, which is the point where a dedicated SEO field makes sense.
With Hydrogen SEO
The plugin prints the description server-side from a template per content type, for example %excerpt% for posts, with a per-post Meta description field in the SEO Settings sheet and a pixel-width preview. A description typed for one post replaces the template for that post only. Templates and overrides are explained in SEO titles and meta descriptions.
Common questions
Does WordPress have a built-in meta description field?
No. Core prints a title tag but no meta description. The excerpt is the closest built-in field, and a snippet or plugin is needed to print it as a description.
Will Google use the description I add?
Often, not always. Google uses the meta description when it describes the page well for the query, and otherwise builds a snippet from the page text.
Is it safe to edit functions.php?
Use a child theme so updates do not overwrite your change, and keep FTP access handy: a syntax error in that file can take the site down until it is fixed.