• Hi Sybre,

    Thanks for a great plugin, love it…

    One feature I miss from Yoast, is the “Strib category base”, since I have no need for the text “category” to show up in my url’s..

    More on the option here

    Are there any plans to include such an option in The SEO framework?

    Have a great day.
    Bjarne

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Bjarne,

    I have no intentions to alter the permalink structure within The SEO Framework on such a level, or any level at all.

    This should be handled by WordPress and it delivers no beneficial SEO value (anymore!).

    TL;DR
    Don’t do anything…

    Reasons:
    1. It’s very technical, users will be confused.
    2. It’s very error prone, the filter below shows unexpected behavior.
    3. It’s very difficult to maintain, if WordPress updates their rewrite rules in any destructive manner according to the filters, I have to revision it.
    4. When a user decides to change it, it can be quite harmful to SEO (links get destroyed).
    5. Long URLs with many “directories” are no longer a major factor in SERP rankings. They can actually be quite helpful according to Matt Cutts.
    6. WordPress has its own options, called “Category Base” beneath the permalink settings.

    About 6, I’ve been told that when you put a . (dot) in it, it will strip the name.

    The dot will be there, but it will be omitted from the URL as the browser nor server can’t process it, this is dealt with very early within the browser and the server.

    You can also go for a more technical approach, a little background:

    When updating the permalink structure, the following happens…

    1. Initializes category base from option update.
    https://github.com/WordPress/WordPress/blob/22adda2aa0abd5a94847b670fd730a443aabdab7/wp-admin/options-permalink.php#L115-L120

    2. Writes those options within permalink structure and flushes the rewrite rules.
    https://github.com/WordPress/WordPress/blob/22adda2aa0abd5a94847b670fd730a443aabdab7/wp-includes/class-wp-rewrite.php#L1902-L1919

    3. Eventually, the rules are being rewritten. And it will look for those rules:
    https://github.com/WordPress/WordPress/blob/22adda2aa0abd5a94847b670fd730a443aabdab7/wp-includes/class-wp-rewrite.php#L1395-L1431

    At step 3, filters are launched! These filters can be used within a plugin or within a theme functions.php file.

    These filters are, by default:

    
    post_tag_rewrite_rules
    category_rewrite_rules

    There are more tags — like product_tag_rewrite_rules, product_cat_rewrite_rules, etc. — depending on the plugins you use.

    For instance, the following filter should remove the base:

    add_filter( 'category_rewrite_rules', 'my_cat_rewrite_rules', 10, 1 );
    function my_cat_rewrite_rules( $rules ) {
    
    	if ( isset( $rules['category/(.+?)/?$'] ) ) {
    		//* Cache value.
    		$val = $rules['category/(.+?)/?$'];
    
    		//* Remove old entry.
    		unset( $rules['category/(.+?)/?$'] );	
    
    		//* Add new entry without 'category/'.
    		$rules['(.+?)/?$'] = $val;
    	}
    
    	return $rules;
    }
    

    Simply after saving the permalink settings for the first after the filter has been implemented, you should notice a difference.

    Final thoughts
    I tested both methods, and the dot seems to be more consistent than the filter. This means that the dot approach removes and redirects the pages correctly.
    However, traces of the dots are found everywhere. In default WordPress URLs the dot will be included, for example.

    The filter approach is safer, it’s recognized correctly by the server and browser. But the old structure still has some traces left in feeds.
    Filtering each of them is a hard thing to do with so many options readily available. Many discussions are also taking place upon this behavior within WordPress Trac.

    My recommendation:
    Use neither approaches. They’re too error prone, that “aha it works” moment can be gone when a plugin or core update is unleashed.

    I hope this clears things up!

    • This reply was modified 8 years, 6 months ago by Sybre Waaijer.
    Thread Starter Bjarne Oldrup

    (@oldrup)

    Oh man Sybre, that’s one reason people enjoy using your plugin so much – your decisions are carefully considered and substantiated. Thanks for clearing things up.

    I chose to use the built in “category base” option, to change the base to “kategori” (category in danish). At least that makes sense in terms of readability and as I use a built in WordPress feature I shouldn’t run into issues any time soon.

    Thank you so much for this detailed explanation regarding the “category base” feature.

    Now go enjoy your weekend ??
    Bjarne

    Plugin Author Sybre Waaijer

    (@cybr)

    Anytime Bjarne!

    It’s a good thing as well, now new visitors from Google will know that the page they’re landing on is a kategori :). It makes the expectation more real.

    Have a wonderful weekend as well :).
    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Option to “strip category base”’ is closed to new replies.