Parsely / Parsely/wp-parsely

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

Open
#3,036 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

wp-parsely
Dominant language
PHP
Stars
66
Forks
36
Avg merge
2d 2h
Merged PRs (30d)
16

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the wp_parsely_post_category filter and the articleSection metadata output, then review the plugin settings area and the Yoast primary-category API described in the issue. Done means an option can enable the behavior when Yoast is active, while posts without a primary category retain the existing category value; verify both paths with the relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
analytics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.