Surprisingly Useful AI Article Enhancements
I get many guest posters asking to add specific meta titles and descriptions to articles but I removed all the big SEO plugins (Yoast, Rank Math etc) that most people use to facilitate this. But, now I’ve a client insisting on adding them or they won’t pay.
I don’t want to add a big SEO plugin to SMBtech as I got paranoid when Google obliterated sites like High Performance Laptops for (seemingly) following best practice rules about web publishing. Us journos certainly don’t follow most rules when publishing articles. So, I’ve got it in my head that being genuine is what matters most to readers… and to Google. Also, it felt like whenever I bothered to add a meta title and description, Google ignored them anyway and made up its own. Also also, big SEO plugins have a bunch of duplicate features that can cause other problems. So, what did I do?
Claude (once again) came to the rescue – and while I didn’t want to add another plug-in Claude explained why I should in this case: you can add code to the functions.php file in WordPress, but any theme updates could overwrite this. Using a child theme is the obvious solution here, but I really like to keep things as basic as possible as I’ve had issues with updating altered child themes in the past. I prefer to use raw themes that have been tested by experts before deployment and I’m more of a web tinkerer who can build functional websites than a code monkey. So, Claude talked me into using a small code-injecting plugin.
In reality I’ve overcomplicated things by creating three steps (you can just paste 3b into your functions.php file), but if you’re looking at this article you’ve probably got some form of coding-related OCD and anxiety about adding something to your entire site, so I’ve included the justifications and outcome of a lengthy Claude conversation to settle any nerves.
Step 1 Install Code Snippets Plugin
Find it here. You don’t need the Pro version for this.
Step 2 Identify if your existing theme has title-tag support
Open Claude (or your favourite AI) and paste:
Does my website at [your URL here] have title-tag support? Check the page source.Step 3a If Yes: Open Code Snippets and do this:
- In Code Snippets, click Add New.
- Give it a name like “Custom Meta Title and Description”.
- Paste the below code above into the code box.
- Click Save Changes and Activate.
- Now open any post or page in the editor. Scroll down below the content area — you’ll see two new boxes: Meta Title and Meta Description. Fill in whichever you need on that post. Leave them blank on posts that don’t need them and the defaults will apply as normal.
- Update/publish the post.
Code if your theme already has title-tag support
// --- Custom Meta Title ---
add_filter('pre_get_document_title', function ($title) {
if (is_singular()) {
$custom = get_post_meta(get_the_ID(), 'custom_meta_title', true);
if ($custom) return $custom;
}
return $title;
});
// --- Custom Meta Description: Add the text box to the editor ---
add_action('add_meta_boxes', function () {
add_meta_box('meta_desc_box', 'Meta Description', 'smbtech_render_meta_desc_box', ['post', 'page']);
});
function smbtech_render_meta_desc_box($post) {
$value = get_post_meta($post->ID, 'custom_meta_description', true);
wp_nonce_field('save_meta_desc', 'meta_desc_nonce');
echo '<textarea name="custom_meta_description" style="width:100%;" rows="3" placeholder="Enter a meta description for this post...">' . esc_textarea($value) . '</textarea>';
}
// --- Custom Meta Description: Save it when the post is saved ---
add_action('save_post', function ($post_id) {
if (!isset($_POST['meta_desc_nonce']) || !wp_verify_nonce($_POST['meta_desc_nonce'], 'save_meta_desc')) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (isset($_POST['custom_meta_description'])) {
update_post_meta($post_id, 'custom_meta_description', sanitize_textarea_field($_POST['custom_meta_description']));
}
});
// --- Custom Meta Description: Output it in the page head ---
add_action('wp_head', function () {
if (is_singular()) {
$desc = get_post_meta(get_the_ID(), 'custom_meta_description', true);
if ($desc) {
echo '<!-- Custom Meta -->' . "\n";
echo '<meta name="description" content="' . esc_attr($desc) . '">' . "\n";
echo '<!-- / Custom Meta -->' . "\n";
}
}
});
// --- Custom Meta Title: Add the text box to the editor ---
add_action('add_meta_boxes', function () {
add_meta_box('meta_title_box', 'Meta Title', 'smbtech_render_meta_title_box', ['post', 'page']);
});
function smbtech_render_meta_title_box($post) {
$value = get_post_meta($post->ID, 'custom_meta_title', true);
wp_nonce_field('save_meta_title', 'meta_title_nonce');
echo '<input type="text" name="custom_meta_title" style="width:100%;" value="' . esc_attr($value) . '" placeholder="Leave blank to use the default post title..." />';
}
// --- Custom Meta Title: Save it when the post is saved ---
add_action('save_post', function ($post_id) {
if (!isset($_POST['meta_title_nonce']) || !wp_verify_nonce($_POST['meta_title_nonce'], 'save_meta_title')) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (isset($_POST['custom_meta_title'])) {
update_post_meta($post_id, 'custom_meta_title', sanitize_text_field($_POST['custom_meta_title']));
}
});Step 3b If No: Open Code Snippets and do this:
- In Code Snippets, click Add New.
- Give it a name like “Custom Meta Title and Description”.
- Paste the below code above into the code box.
- Click Save Changes and Activate.
- Now open any post or page in the editor. Scroll down below the content area — you’ll see two new boxes: Meta Title and Meta Description. Fill in whichever you need on that post. Leave them blank on posts that don’t need them and the defaults will apply as normal.
- Update/publish the post.
Code if your theme DOES NOT HAVE title-tag support
// --- Add title-tag support (skip if your theme already has it) ---
add_theme_support('title-tag');
// --- Custom Meta Title ---
add_filter('pre_get_document_title', function ($title) {
if (is_singular()) {
$custom = get_post_meta(get_the_ID(), 'custom_meta_title', true);
if ($custom) return $custom;
}
return $title;
});
// --- Custom Meta Description: Add the text box to the editor ---
add_action('add_meta_boxes', function () {
add_meta_box('meta_desc_box', 'Meta Description', 'smbtech_render_meta_desc_box', ['post', 'page']);
});
function smbtech_render_meta_desc_box($post) {
$value = get_post_meta($post->ID, 'custom_meta_description', true);
wp_nonce_field('save_meta_desc', 'meta_desc_nonce');
echo '<textarea name="custom_meta_description" style="width:100%;" rows="3" placeholder="Enter a meta description for this post...">' . esc_textarea($value) . '</textarea>';
}
// --- Custom Meta Description: Save it when the post is saved ---
add_action('save_post', function ($post_id) {
if (!isset($_POST['meta_desc_nonce']) || !wp_verify_nonce($_POST['meta_desc_nonce'], 'save_meta_desc')) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (isset($_POST['custom_meta_description'])) {
update_post_meta($post_id, 'custom_meta_description', sanitize_textarea_field($_POST['custom_meta_description']));
}
});
// --- Custom Meta Description: Output it in the page head ---
add_action('wp_head', function () {
if (is_singular()) {
$desc = get_post_meta(get_the_ID(), 'custom_meta_description', true);
if ($desc) {
echo '<!-- Custom Meta -->' . "\n";
echo '<meta name="description" content="' . esc_attr($desc) . '">' . "\n";
echo '<!-- / Custom Meta -->' . "\n";
}
}
});
// --- Custom Meta Title: Add the text box to the editor ---
add_action('add_meta_boxes', function () {
add_meta_box('meta_title_box', 'Meta Title', 'smbtech_render_meta_title_box', ['post', 'page']);
});
function smbtech_render_meta_title_box($post) {
$value = get_post_meta($post->ID, 'custom_meta_title', true);
wp_nonce_field('save_meta_title', 'meta_title_nonce');
echo '<input type="text" name="custom_meta_title" style="width:100%;" value="' . esc_attr($value) . '" placeholder="Leave blank to use the default post title..." />';
}
// --- Custom Meta Title: Save it when the post is saved ---
add_action('save_post', function ($post_id) {
if (!isset($_POST['meta_title_nonce']) || !wp_verify_nonce($_POST['meta_title_nonce'], 'save_meta_title')) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (isset($_POST['custom_meta_title'])) {
update_post_meta($post_id, 'custom_meta_title', sanitize_text_field($_POST['custom_meta_title']));
}
});Claude points out that the first add_theme_support('title-tag') line is the only difference and that if a theme already declares it, having it twice is harmless – WordPress just ignores the duplicate.
Image of Code Snippets Plugin

Here’s what it now looks like when creating a new post

Thank you Claude (again).
Last Updated on August 30, 2026 by Nick Ross


