Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jblz opened this issue Dec 30, 2024 · 0 comments
Open

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

jblz opened this issue Dec 30, 2024 · 0 comments

Comments

@jblz
Copy link
Contributor

jblz commented Dec 30, 2024

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

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

No branches or pull requests

1 participant