WordPress.org

Ready to get started?Download WordPress

Forums

Remove Parent Categories from Category URL (6 posts)

  1. Burke Ingraffia
    Member
    Posted 3 years ago #

    Since I upgraded to 3.1 I have had an issue with my category URLs.

    In 3.0.5 (using All-in-one-SEO) if I had parent categories like

    http://www.mysite.com/category/parent-1/parent-2/child/

    The URL would be http://www.mysite.com/category/child/

    Now it's back to showing the parents. Did something change in the wp-includes/category-template.php file?

    How do I remove parent categories from the urls?

  2. mr_doinel
    Member
    Posted 3 years ago #

    I have got exactly the same issue.
    Is it possible to remove the parent category from the url with WordPress 3.1 ?

  3. mr_doinel
    Member
    Posted 3 years ago #

    Any ideas about this new issue ?

  4. mr_doinel
    Member
    Posted 3 years ago #

    I finally find a way to change this!

    Put this code in your functions.php fiel :

    add_action( 'init', 'build_taxonomies', 0 );  
    
    function build_taxonomies() {
    
      register_taxonomy( 'category', 'post', array(
    		'hierarchical' => true,
    	 	'update_count_callback' => '_update_post_term_count',
    		'query_var' => 'category_name',
    		'rewrite' => did_action( 'init' ) ? array(
    					'hierarchical' => false,
    					'slug' => get_option('category_base') ? get_option('category_base') : 'category',
    					'with_front' => false) : false,
    		'public' => true,
    		'show_ui' => true,
    		'_builtin' => true,
    	) );
    
    }

    Setting the hierarchical parameter of the rewrite parameter to false does the job perfectly! :)

  5. Burke Ingraffia
    Member
    Posted 3 years ago #

    That worked, but the way it was before I switched to 3.1 was that if you did land on

    http://www.mysite.com/category/parent-1/parent-2/child/

    It would redirect to

    http://www.mysite.com/category/child/

    Thanks for the tip - I love learning.

  6. ballhogjoni
    Member
    Posted 2 years ago #

    awesome dude, just what I was looking for :)

Topic Closed

This topic has been closed to new replies.

About this Topic