Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.75k stars 886 forks source link

Restore the article:section and article:tag Open Graph tags #15101

Open collinkrawll opened 4 years ago

collinkrawll commented 4 years ago

Is your feature request related to a problem? Please describe.

Both article:section and article:tag are a core part of the Open Graph spec (see: https://ogp.me/#no_vertical). They allow systems to categorize the content of the page based on the publisher's preferences. They are used by various indexers for categorizing the content of the page. In our case, we are using these tags to determine which ads to show.

Describe the solution you'd like

Please restore the article:section and article:tag Open Graph tags.

Why do you think this feature is something we should consider for the Yoast SEO plugins?

Millions of pages that previously published data regarding how to properly categorize their content just dropped it. It should be pretty easy to put back in.

Additional context

I couldn't find any information online about these tags being deprecated by Facebook or from the Open Graph standard. Even if they aren't used by Facebook, smaller search engines and crawlers are likely using them.

If there is a reason why some sites might not want them, a switch could possibly be added to turn them on/off.

collinkrawll commented 4 years ago

@Xyfi Can you add some context to the decision to remove these tags in #13790?

collinkrawll commented 4 years ago

It looks like we could potentially pull the section and tags from the Article/articleSection and Article/keywords properties of the Schema.org JSON-LD. But it looks like those are only included in the schema if the site has configured the organization name and logo in their Yoast SEO settings (which enables the Article section of the JSON-LD schema).

Djennez commented 4 years ago

More relevant information on this is provided here: https://github.com/Yoast/wordpress-seo/issues/10282#issuecomment-623331810 . There is also a filter in there that you can use to add the tag (amongst others) to our header section again.

mayada-ibrahim commented 4 years ago

Please inform the customer of conversation # 611047 when this conversation has been closed.

collinkrawll commented 4 years ago

Another issue that we just discovered is that the "primary category" of the post no longer seems to be published (neither in the Open Graph tags nor the Schema.org schema). In WordPress, you choose the primary category for a Post in the Post settings just below where you choose the categories.

In v13 of the Yoast SEO Plugin, whichever category you picked as the primary category for the post would be the one that would appear in the article:section Open Graph tag.

As mentioned above, in v14 of the Yoast SEO Plugin, the article:section Open Graph tag was dropped. The categories do appear in the Schema.org schema (in the Article/articleSection property) but they appear in alphabetical order. Changing the primary category doesn't seem to have any effect on the Schema, so there no longer seems to be any way for third parties to determine which is the primary category for the post.

Djennez commented 4 years ago

@collinkrawll The primary category was also introduced to reflect in the permalink if you use %category% in your permalinks. And indeed, it isn't output anywhere by default on posts anymore. But like stated above: you can reintroduce the article:section again with the provided filter, and you can get the primary category of a post and reflect that in that tag.

The primary category is also used if you use the category path in your breadcrumbs.

davidmondok commented 4 years ago

For anyone looking for a solution to add back the article:tag meta tags, this is how we solved it

add_filter( 'wpseo_frontend_presenters', 'filter_presentation_classes', 10, 1);
function filter_presentation_classes( $presentation ) {
    if ( ! class_exists( 'Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter' ) ) {
        return $presentation;
    }

    $tags = get_the_tags();

    if (empty($tags)) {
        return $presentation;
    }

    class Section_Presenter extends Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter {
        /** @var string */
        private $tag;

        public function __construct(string $tag) {
            $this->tag = $tag;
        }
        protected $tag_format = '<meta property="article:tag" content="%s" />';
        public function get() {
            return $this->tag;
        }
    }

    foreach ($tags as $tag) {
        $presentation[] = new Section_Presenter($tag->name);
    }

    return $presentation;
}