To add keywords (also known as meta keywords) to your WordPress website without using plugins, you’ll need to manually edit your theme files or utilize functions.php file to add custom code. Here’s how you can do it:
Access Theme Files:
Log in to your WordPress admin panel, then navigate to Appearance > Theme Editor
. This will allow you to edit your theme files directly. or create a child theme on there and upload it and Edit Functions.php:
You can add the code in child theme functions.php
file
add_action('wp_head', function (){
if( is_single() || is_page() ) {
$meta_keywords_raw = (get_post_meta(get_the_ID(), 'keywords', true));
if ($meta_keywords_raw) {
$meta_keywords = preg_replace('/\s*,\s*/', ', ', $meta_keywords_raw);
?>
<meta name="keywords" content="<?= $meta_keywords; ?>">
<?php }} } );
If you choose functions.php
, it’s generally located under your theme’s directory as well.
Insert the following code within the <head>
section of your functions.php
file: Go to the page or POSTS and paste your keyword. Before posting follow this way.
- Enable CUSTOM Fields
- Save Changes:
After adding the code, make sure to save the changes you made to the file. - Verify:
Once saved, you can verify that the meta keywords are added to your site’s source code by viewing the page source in your browser. Right-click on your website and select “View Page Source”. Then search for the meta keywords tag to ensure it’s there.
- Test:
Test your website to ensure that the keywords are being properly read by search engines. You can do this by searching for your site on Google and checking the meta description under your website link.
Remember, while adding meta keywords directly is a method, search engines like Google largely ignore them as a ranking factor. They prioritize other elements like quality content, backlinks, and user experience. So, while it’s okay to add meta keywords, don’t solely rely on them for SEO. Focus on creating high-quality content and optimizing other SEO factors.