WordPress link button does not recognize primary category permalink
What did you expect to happen?
WordPress to insert link using the primary category permalink.
What happened instead?
WordPress inserts the link using the categories in alphabetical order instead of the primary category permalink.
How can we reproduce this behavior?
- Configure the permalinks as /%category%/%postname%/
- Create new categories: category01, category02, category03
- Create a new post, assign category03 as primary category, this would make the URL /category03/postname.

-
In another post, insert a link using the WordPress link button.

-
Check that WordPress suggests the /category01/ link instead of the /category03/ permalink.

Technical info
- WordPress version: 4.7.5
- Yoast SEO version: 4.8
Please inform the customer of conversation # 200046 when this conversation has been closed.
This user in the free forum is experiencing the same issue https://wordpress.org/support/topic/primary-category-function-not-working-correctly/
Related https://wordpress.org/support/topic/problem-with-categories-yoast/
The user here also experiencing this issue: https://wordpress.org/support/topic/primary-taxonomy-not-reflected-in-url/
Same issue. Any solutions?
This issue still happens in Yoast SEO v14.5 but only when a link is added using the Classic Editor, not Gutenberg.
Please inform the customer of conversation # 630299 when this conversation has been closed.
This issue also happens with Yoast SEO Premium v15.0. I would've thought getting the right URL showing with an SEO plugin is a little more important than "trivial"! :)
Please inform the customer of conversation # 728038 when this conversation has been closed.
Still reproducible with Yoast SEO 18.6 and Classic Editor 1.6.2. It seems that not always the first category in alphabetical order is chosen. In my tests, when a post link is inserted, the Classic Editor includes the original category (the first category that was assigned to the post) in the permalink instead of the primary category.
Please inform the customer of conversation # 884845 when this conversation has been closed.
The issue moved to internal issue management board. I can confirm the issue is no longer only specific to the Classic Editor but occurs on Gutenberg editor as well.
Issue still reproducible in Yoast SEO 20.5 and Classic Editor 1.6.3. Re-opening.
can't wait for this to be fixed! makes us second guess using yoast primary category with our URLs
Please inform the customer of conversation # 1069404 when this conversation has been closed.
Please inform the customer of conversation # 1112593 when this conversation has been closed.
Initial investigation:
- It seems that we can hook into the search behaviour with
add_action( 'wp_ajax_wp_link_ajax',. We can investigate if we can make sure to include the primary term in the link instead of another term.