• Resolved digitalmediafbm2021

    (@digitalmediafbm2021)


    Hi,

    we are tryring to use the YOAST SEO primary category.
    All the settings are according to your implementation.
    Our categories are set up in that order:

    category1 -> Subcategory1
    category2 -> Subcategory2

    My goal is to create posts where the URL would be: category1/subcategory 1/ where subcategory1 is the primary category, even though we would also check a subcategory 2 under “category2”. The plugin unfortunately does not realize this and generates the URL in this order: category2/subcategory2/ – even though it should be category1/subcategory1.

    We tried a few steps and it actually works if we safe a draft before we publish it. It generates the URL then in the right order. Was there a new update on the plugin that confuses the order of how the URI s will be generated?

    Is there any setting that the URL will always be generated including the primary category?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @digitalmediafbm2021,

    Hmm, there was no change in the way the primary category is used in the default permalinks. If the custom permalink is generated for the first time, Permalink Manager will still respect it.

    I believe the issue is caused by the new option that allows you to choose whether or not to save custom permalinks for drafts. In particular, based on the “Exclude drafts” settings, you can now generate custom permalinks only after the post has been published. Could you try to toggle it and check if the issue persists?

    Edit: If necessary, you can always use URI Editor to see how the default permalink should be constructed:
    https://permalinkmanager.pro/docs/basics/bulk-edit-wordpress-permalinks/#2-how-to-preview-new-custom-permalink-format

    Best regards,
    Maciej

    • This reply was modified 2 years, 3 months ago by Maciej Bis.
    Thread Starter digitalmediafbm2021

    (@digitalmediafbm2021)

    Hi Maciej,

    thanks for your fast response!
    I toogled both options and both times the URI Editor first saves the posts as “uncategorized” ( even tho i chose the categories aswell as the primary category).
    Then after going in previewmode / reloading the edit page it changes to the subcategory 2 again but not the primary category.
    Here are the permastructure settings: %category%/%postname%-%post_id%

    Thanks for your help! ( btw. we updated also to pro… but no changes there)

    Plugin Author Maciej Bis

    (@mbis)

    Hi @digitalmediafbm2021,

    Could you by any chance send me the screenshot with URI Editor opened, so I can check how the default permalink format is displayed? You can find the instructions on how to open it using the link in my response above.

    Thread Starter digitalmediafbm2021

    (@digitalmediafbm2021)

    Hi Maciej,

    here is the structure:
    https://prnt.sc/26frs62

    1. I create the post and set the categories ( Subcat 1 = primary category; sub 2 is just checked but should not show up in URL. Parents are Sub1: “News”; Sub2: “Themen”;
    https://prnt.sc/26frsml

    2. I publish the post directly and the URI is the following:
    https://prnt.sc/26frthj (Uncategorized)

    3. With a reload of the edit page and also in the preview mode an automated reload apears the URI changes to themen/sub2 (not primary)
    https://prnt.sc/26frubo

    4. Im making the post to a draft again and safe it as a draft. Now I publish it again and the URI is now the right version (News/Sub1)
    https://prnt.sc/26fruyy

    To reduce error we don’t want to add effort for our writers, to always go through all these steps, as we think it is a bug and should load from the beginning the correct URI.

    We are using the SEO Yoast Plugin aswell. Connection should be right though, as it is working correctly after the 4th step.

    Plugin Author Maciej Bis

    (@mbis)

    Thank you @digitalmediafbm2021,

    I understand the problem now. The primary category option does not appear to be saved by Yoast SEO at the time the URI is produced and saved. I will try to fix it within 24 hours and provide you with a temporary hotfix solution.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @digitalmediafbm2021,

    Could you try to paste the below snippet to functions.php in child theme directory? This is only a temporary solution, since the problem will be fixed in the plugin’s next release.

    function pm_yoast_primary_term_fix($category_slug, $term, $post, $terms, $taxonomy) {
    	if(class_exists('WPSEO_Primary_Term') && class_exists('WPSEO_Meta')) {
    		$yoast_primary_term_label = sprintf('yoast_wpseo_primary_%s_term', $taxonomy);
    
    		// Hotfix: Yoast SEO saves the primary term using 'save_post' hook with highest priority, so the primary term ID is taken directly from $_POST
    		if(!empty($_POST[$yoast_primary_term_label])) {
    			$yoast_primary_term_id = filter_input(INPUT_POST, $yoast_primary_term_label, FILTER_SANITIZE_NUMBER_INT);
    
    			$primary_term = (is_numeric($yoast_primary_term_id)) ? get_term($yoast_primary_term_id, $taxonomy) : '';
    
    			if(!empty($primary_term) && !is_wp_error($primary_term)) {
    				$primary_term_slug = Permalink_Manager_Helper_Functions::get_term_full_slug($primary_term, $terms, false, false);
    			}
    		}
    	}
    
    	return (!empty($primary_term_slug)) ? $primary_term_slug : $category_slug;
    }
    add_filter('permalink_manager_filter_term_slug', 'pm_yoast_primary_term_fix', 10, 5);
    Thread Starter digitalmediafbm2021

    (@digitalmediafbm2021)

    Thank you Maciej,

    it seems to work just fine!

    Plugin Author Maciej Bis

    (@mbis)

    Perfect, you can remove the snippet after 2.2.16 version is released. The code I sent you will be included directly in the Permalink Manager functions 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Primary Category SEO Yoast’ is closed to new replies.