Reputation: 12663
The excellent Yoast SEO plugin is adding some unwanted meta tags.
For example, I would like article:author
to appear on posts, but not on pages or other content types.
Is there a way to adjust this globally?
I'm happy to edit functions.php
, but I'm just unsure what I should be hooking in to.
I would be grateful for any pointers from those more familiar with the plugin.
I tried this:
function wpseo_show_article_author_only_on_posts() {
if ( !is_single() ) {
return false;
}
}
add_filter( 'xxxxxx', 'wpseo_show_article_author_only_on_posts' );
I need to know what hook should replace xxxxxx
.
Upvotes: 1
Views: 5640
Reputation: 911
If people are looking for a way to remove more yoast SEO tags, just lookup the file wordpress-seo/frontend/class-opengraph.php, and you can see which filters you can hook into to remove certain tags.
This is the code I use to remove these tags from pages: url, image, title, description and type:
function remove_yoast_og_tags( $ogTag ){
// Do a check of which type of post you want to remove the tags from
if ( is_page() ) {
return false;
}
return $ogTag;
}
$yoastTags = array(
"url",
"image",
"title",
"desc",
"type"
);
foreach ($yoastTags as $tag) {
add_filter( 'wpseo_opengraph_'.$tag, 'remove_yoast_og_tags');
}
Upvotes: 1
Reputation: 9843
You're looking for the wpseo_opengraph_author_facebook
filter, which ties into the article_author_facebook()
method in frontend/class-opengraph.php
of the plugin.
function wpseo_show_article_author_only_on_posts( $facebook ) {
if ( ! is_single() ) {
return false;
}
return $facebook;
}
add_filter( 'wpseo_opengraph_author_facebook', 'wpseo_show_article_author_only_on_posts', 10, 1 );
The article_author_facebook()
method does a check for is_singular()
, which checks that we're viewing single page, post or attachment:
This conditional tag checks if a singular post is being displayed, which is the case when one of the following returns true:
is_single()
,is_page()
oris_attachment()
. If the$post_types
parameter is specified, the function will additionally check if the query is for one of the post types specified.
The additional filter for ( ! is_single() )
ensures that article:author
is only added to posts.
Upvotes: 3