Removing article:tag from Yoast’s WordPress SEO plugin

Yoast Logo Large RGB

Scroll down for the code since i’m a little long-winded on this post. Ye’ve been warned.

Yoast’s WordPress SEO plugin is awesome at getting you quickly setup with adding Twitter Cards and Facebook OpenGraph data to your website. But over the latest iterations it’s either added superfluous meta data or removed the options to toggle what is or isn’t shown (version 7.1 is a big culprit of it, which is currently running on this site, and i should just downgrade, but i like to run this site as bleeding edge, learning daily, so it’ll stay).

Two pieces of superfluous meta data that i wanted to remove are the article:tag and article:category <meta> tags that Yoast likes to display on pages that use those taxonomies.

Backstory: i’m currently working on a project where i’ve run into the need to limit edit access to certain pages, but got turned all the way around with user roles and plugins and whatnot, but yesterday i found a possible solution using tags: if a page was tagged with something like “editor-can-edit”, then the user (which is assigned the built-in Editor role) could edit said page, but wouldn’t see pages without that tag on the Edit Pages page. Awesome. The issue i noticed immediately when i was searching for the CSS class .tag-editor-can-edit, which is assigned to each applicable <tr> on the Edit Page page, was that Yoast all willy-nilly decided to output all the tags the page was using. Not sure i like that. No security threat or anything, just it’s clogging up the <head> and putting unnecessary <meta> tags.

I had to find a solution. After about two hours — yes, really — of scouring StackOverflow, reading countless StackExchange posts, the Codex, as well as various articles, trying everything and all the things, i figured out what to do! I got tripped up a bit but learned a great deal, actually, about how the add_action / remove_action and add_filter / remove_filter joints worked in WordPress, especially when attempting to use such on external classes (from plugins for instance like WPSEO!). It was a pain to wrap my brain around. But i got it. I believe.

One of the things that got me was understanding that i needed to find the instance of the class, in this case WPSEO_OpenGraph, that was used by WPSEO to output the OpenGraph data, and then call said instance. That’s done by the simple global $wpseo_og; that you see above. So the tricky part for me was finding where it’s originally called and then why/how to use it.

So, i dove into the actual plugin files — but not wanting to just comment out lines so i had to learn how to hook into it. In the wp-seo-main.php file, line 353, you’ll see this $GLOBALS['wpseo_og'] = new WPSEO_OpenGraph();

From there, the next line is to remove the action, and this action as specified in the class-opengraph.php file under the class WPSEO_OpenGraph is ‘wpseo_opengraph’ which then looks for ‘tags’ and ‘category’ amongst several other options. That ’16’ you see is the priority, and since wpseo_opengraph adds the action at the priority of 16, you gotta remove the action at the same.

And that’s basically it. The gist above also you’ll see has code to remove the article:category. I originally didn’t include it. Oh, and since we’re talking about removing annoying Yoast stuff, below is a gist with a function to remove the annoying — and potential security risk —

 <! -- This site is optimized with the Yoast WordPress SEO plugin v6.0 -- > 

from the <head> of all your pages. Thank you, Paul Collet.

All right. Happy coding, y’all! Cheers.

(Visited 174 times, 1 visits today)

If you found this post useful ...

Buy Me a Coffee logo
Wondering why you keep seeing lower-cased 'i' in my posts? Read -> Why ‘i’ is not capitalized
5 1 vote
Article Rating
Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
5 years ago

Thank you so much that is exactly what I was looking for.
I was missing the $wpseo_og

Would love your thoughts, please comment.x