How to Add Custom Meta Tags to HTML Head in WordPress via functions.php

Custom meta tags are crucial for a strong SEO strategy, helping website owners tell a unique story about their WordPress sites across different online platforms. These tags not only affect how a website appears in search results but also shape its look on social media, Google Search Console, and other important online places.

Meta tags, like those used for Open Graph (OG) and Google Search Console verification, are essential tools for improving how people see and interact with your WordPress website. They give you a structured way to control how your website content looks on places like social media and search results.

In this tutorial, we’ll explore specific meta tags, including Open Graph (OG) tags, Google Search Console verification tags, viewport meta tags for responsive design, author meta tags for content attribution, robots meta tags for guiding search engines, and keywords meta tags for categorizing content. You can easily add all of these directly into the HTML head of your WordPress website using the functions.php file.

Before proceeding with any customizations in WordPress, it’s essential to set up a child theme. A child theme acts as a safe and efficient way to make modifications without affecting the parent theme. If you haven’t set up a child theme yet, follow this tutorial on How to Create a Child Theme for Customization. It will guide you through the process and ensure that your customizations remain intact even after theme updates.

Sample Meta Tags:

<meta name="key" content="value" />
<meta name="author" content="Your Name">
<meta name="robots" content="index, follow">
<meta name="keywords" content="keyword1, keyword2" />
<meta name="description" content="this is the description of this page" />
<meta name="facebook-domain-verification" content="abcdefghijklmnopqrstuvwxyz" />
Code language: HTML, XML (xml)

Customize functions.php in Child Theme

To begin, open your WordPress child theme’s functions.php file. This file is like the control center for tweaking your theme’s functionality. You can edit it directly within the Theme Editor (Appearance > Theme File Editor > Your child theme > functions.php) in your WordPress dashboard or use an external code editor with FTP for more advanced changes. Insert the provided code snippet at the end of the functions.php file to make the desired changes.

 * Add custom Meta Tag to header.
function custom_header_metadata() {
	echo '<meta name="your-meta-name" content="your-meta-content">';
	echo '<meta name="author" content="Your Name">';
	// Add more meta tags as needed
add_action( 'wp_head', 'custom_header_metadata' );
Code language: PHP (php)

Replace "your-meta-name" and "your-meta-content" with the desired name and content for your custom meta tag. You can add as many custom meta tags as you need by repeating the code and changing the name and content accordingly.

Save and Test Your functions.php Modifications

Once you have added the custom meta tags, save the functions.php file and upload it to your website. To ensure that your custom meta tags are successfully integrated, follow these steps:

  1. Visit Your Website: Open a new tab in your browser and visit your WordPress website.
  2. Right-Click and Inspect Element: Right-click on any part of your webpage and select “Inspect” or “Inspect Element” from the context menu. This will open the browser’s Developer Tools.
  3. Navigate to the Head Section: In the Developer Tools, navigate to the “Elements” or “Inspector” tab and locate the <head> section. Ensure that your custom meta tags are visible within the <head> section.
  4. Check the Source Code: View the page’s source code by right-clicking on the webpage and selecting “View Page Source” or “Inspect,” then navigate to the head section (<head>...</head>). Confirm that your custom meta tags are present in the source code.

By following these steps, you can confirm the successful addition of custom meta tags to the HTML head of your WordPress website. This ensures that search engines and other platforms will recognize and use the specified meta information.

That’s it! You’ve successfully integrated targeted meta tags into your WordPress website, enhancing its online presence and SEO strategy. By incorporating Open Graph (OG) tags, Google Search Console verification, and other key meta tags, you’ve taken a proactive step toward shaping how your site is portrayed across various platforms.

Custom meta tags provide control over your website’s description, display, and visibility in search results, enhancing its professional appearance and discoverability on social media.

The provided code is versatile, allowing customization and expansion of your meta tags. Whether you’re a blogger or managing a business site, optimizing with these meta tags is a valuable investment in online success.

Leave your feedback and help us improve 🐶

We hope you found this article helpful! If you have any questions, feedback, or spot any errors, please let us know in the comments. Your input is valuable and helps us improve. If you liked this article, please consider sharing it with others. And if you really enjoyed it, you can show your support by buying us a cup of coffee ☕️ or donating via PayPal 💰.

More free knowledge, because why not?

One Comment

Your thoughts matter, leave a reply 💬

Your email address will not be published. Required fields are marked *