You can add a keywords meta tag with a few lines of code in a child theme, and this guide shows how. But Google has ignored the tag since 2009 and Bing reads it mainly as a spam signal, so first decide whether you need it at all, and what to set instead.
Add a custom field called meta_keywords to the page, and a short function in a child theme’s functions.php that prints it in the page head. The steps and code are below. Before you start, know what the tag does today:
For search, the page title and meta description are what count. Keywords are worth adding only if something else reads them, such as an internal search tool, or a client brief that asks for them.
Put the code in a child theme, so a theme update doesn’t wipe it out. A child theme is a folder in wp-content/themes with two files. For Twenty Twenty-Five, style.css needs just this header:
/*
Theme Name: Twenty Twenty-Five Child
Template: twentytwentyfive
*/Add a functions.php file next to it, then activate the child theme under Appearance > Themes. WordPress’s child theme guide covers the details. Block themes load functions.php just like classic themes do.
Paste this into the child theme’s functions.php. The first line, <?php, has to be the very first thing in the file. The function prints a keywords tag on any page or post that has a meta_keywords custom field, and nothing anywhere else:
<?php
add_action( 'wp_head', 'mytheme_meta_keywords' );
function mytheme_meta_keywords() {
if ( ! is_singular() ) {
return;
}
$keywords = get_post_meta( get_queried_object_id(), 'meta_keywords', true );
if ( $keywords ) {
echo '<meta name="keywords" content="' . esc_attr( $keywords ) . '">' . "\n";
}
}Test on a staging copy first: a typo in functions.php can take the site down until it’s fixed.
<meta name="keywords"> line should be in the head.If you only want one keywords tag on the homepage, skip the custom field and put this function under the first line of functions.php instead:
add_action( 'wp_head', 'mytheme_home_keywords' );
function mytheme_home_keywords() {
if ( is_front_page() ) {
echo '<meta name="keywords" content="wordpress agency, care plans, website support">' . "\n";
}
}Keep it short and true to the page: a long list of unrelated terms is exactly what Bing treats as a spam signal.
Code in a theme leaves with the theme. If the site might switch themes, put the same function in a single file in wp-content/mu-plugins instead, starting with the same first line. WordPress loads every PHP file placed directly in that folder, with no activation step, so the tag survives a theme change. Strictly speaking that is a small plugin, but there is nothing to install from the directory or update.
New to the basics? See how to use WordPress.
Head tags are a small change in a risky place. With WPOS, the agent works inside wp-admin on your site: you describe the change, it makes it, and it checks the page before it reports back.
“Add a keywords meta tag to the product pages from a custom field, then check it appears on three of them.”
WPOS is our product, so weigh this section accordingly; you can try it free for 30 days with 5,000 credits, a live site plus a staging sandbox, and no card.
No. Google announced in 2009 that its web search disregards the keywords meta tag in ranking.
No. WordPress doesn't output a keywords tag on its own; you add it with code or a plugin.
Google ignores them. Bing has said it uses the tag mainly to detect spam, so a long list of unrelated terms could count against a site there.
In the page head. The function above hooks into wp_head, which every theme prints inside the head.
Yes. Block themes load functions.php like classic themes, so the same code works in a child theme of Twenty Twenty-Five.
The title tag, the meta description, the headings and copy, internal links and structured data.
WPOS puts an AI agent inside wp-admin that builds natively in Gutenberg, Elementor and Divi and checks its own work. Free for 30 days: 5,000 credits, a live site plus a sandbox, no card.
Start free