Find out how you can improve the way your category pages are displayed when you share them by adding Open Graph meta tags.
Open Graph is a protocol that allows you to define how links to your content are presented when shared on social networks. In WordPress, it serves to improve the appearance and effectiveness of shared posts, ensuring that they are displayed with the desired title, description and image.
Most SEO plugins usually include the basic functions.
But if, for example, you have added an image to the categories, it will not be displayed when you share them.
In this tutorial we are going to see how you can add custom metadata to display the image and other tags.
Snippet for adding metadata to Open Graph on category pages
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this code you use the wp_head
hook in conjunction with the is_category
conditional tag, to add extra metadata to the category page.
Specifically, it takes the image of a custom field created with ACF, but you can modify it to take the custom field you need.
These are the tags you add to Open Graph:
<meta property="og:type">
<meta property="og:title">
<meta property="og:description">
<meta property="og:image">
<meta property="og:url">
Conclusions
Now you know how to get a category image displayed when you share it on social networks (or messaging applications).
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂