Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using WooCommerce for a shopping site and it is adding slug or base to the urls. For instance: http://dev.unwaveringmedia.com/8dim/product-category/all-party-supplies/ http://dev.unwaveringmedia.com/8dim/product/14-snowman-serving-tray/

I don't want slug/base (product & product-category) in urls.

Is there any way or plugins to remove them from urls?

share|improve this question
add comment

put on hold as off-topic by toscho Apr 17 at 19:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Found this neat little article on it, try this out!

http://ryansechrest.com/2013/04/remove-post-type-slug-in-custom-post-type-url-and-move-subpages-to-website-root-in-wordpress/

It's a guide/tutorial, so you should be able to get more information on what's going on here if you visit his site.

By the way, it's against the rules to ask for a plugin here.

add_action(
  'pre_get_posts',
  'custom_pre_get_posts'
);

function custom_pre_get_posts($query) {
    global $wpdb;

    if(!$query->is_main_query()) {
      return;
    }

    $post_name = $query->get('pagename');

    $post_type = $wpdb->get_var(
      $wpdb->prepare(
        'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s LIMIT 1',
        $post_name
      )
    );

    switch($post_type) {
      case 'services':
        $query->set('services', $post_name);
        $query->set('post_type', $post_type);
        $query->is_single = true;
        $query->is_page = false;
        break;
    }

    return $query;
}
share|improve this answer
    
Thanks it help me in some way to find the solution. –  Irfan Dayan Jan 20 at 7:47
    
Great, I'm glad I could help. It's amazing what Google can turn up if you find the right query. –  MrJustin Jan 20 at 9:29
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.