Skip to content

Add Option to use Yoast "Primary Category" value for section in metadata #3036

Description

@jblz

Is your feature request related to a problem?

The (very popular) Yoast SEO plugin has functionality to specify a "Primary Category" that's useful when a post is classified as more than one category:

https://yoast.com/help/how-to-select-a-primary-category/

If it's present, It would be nice to treat this value as the one that is used to declare the articleSection portion of the metadata output by this plugin.

Check out 198625-z for an instance where the value for the Primary Category feature was expected to determine the dashboard section for posts.

Describe the solution you'd like

It might be worth an option in the plugin settings page to enable this behavior when the Yoast SEO plugin is detected and active.

Describe alternatives you've considered

There's a workaround to achieve this behavior that looks like this:

function sgf_override_parsely_category_with_yoast_primary ( $category_name, $post_obj, $parsely_options ) {
   if ( ! function_exists( 'yoast_get_primary_term' ) ) {
     return $category_name;
   }
   $primary_category = yoast_get_primary_term( 'category', $post_obj );
   return strlen( $primary_category ) ? $primary_category : $category_name;
}
add_filter( 'wp_parsely_post_category', 'sgf_override_parsely_category_with_yoast_primary', 10, 3 );

yoast_get_primary_term is a function that was added 8+ years ago, so it ought to be stable enough for this purpose.

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wp-parselyRequired label for all issues

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions