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

Custom meta tags are an important part of a website’s SEO strategy. By adding custom meta tags to the HTML head of a WordPress website, website owners can control how their website is described and displayed in search engine results. Custom meta tags can also be used to add specific information to a website’s head, such as social media descriptions and other important information.

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.

In this tutorial, we will show you how to add custom meta tags to the HTML head of a WordPress website via the functions.php file.

Meta tags look like this:

<meta name="key" content="value" />
<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)

To get started, you will need to access the functions.php file of your WordPress theme. You can do this by logging into your website’s backend and navigating to Appearance > Theme File Editor > Your child theme > functions.php

Once you have accessed the functions.php file, you will need to add the following code:

* Add custom Meta Tag to header. 

function custom_header_metadata() {

	echo '<meta name="your-meta-name" content="your-meta-content">';

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.

Once you have added the custom meta tags, save the functions.php file and upload it to your website.

That’s it! Adding custom meta tags to the HTML head of a WordPress website via the functions.php file is a simple and effective way to improve your website’s SEO and control how your website is displayed in search engine results. By following the steps outlined in this tutorial, you can easily add custom meta tags to your WordPress website and start optimizing your website for search engines.

Thats it!

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 *