WordPress.org

Ready to get started?Download WordPress

Forums

How to remove /blog/ prefix for custom post types in permalinks? (6 posts)

  1. nikoza
    Member
    Posted 2 years ago #

    I have a client that used to have a static website and a blog powered from WordPress under the /blog subdirectory. Now he decided to move everything into WordPress so that he can also create and edit pages easily. However because the website is getting a lot of traffic and he already has likes, tweets and +1 in every blog post he wants to keep his blog under the website.com/blog. I thought it was as easy as heading over the permalinks and add /blog/%postname%/ in the permalink structure.

    What the problem is right now is that I have a created a few custom post types to accommodate the needs of his content and custom post type's content resides now under the blog virtual directory.

    How can I specify that only the blog posts and the blog categories must be under the /blog virtual directory and everything else can use the permalink structure of /%postname%/.

    [No bumping. If it's that urgent, consider hiring someone.]

  2. brianj
    Member
    Posted 2 years ago #

    I'm trying to achieve the exact same thing....tried everything I can think of....seems that it works if you don't use a custom permalink (in our case, we are using /blog/%postname)....if you select one of the radio button options in the permalinks settings page, your custom post types will be how we want them e.g. domain.com/custom-post-type.

    Guess I'll keep googling...would love someone to chime in :)

  3. dannymoe34
    Member
    Posted 2 years ago #

    I also search soulotion for this problem. I think this option need to be default on wordpress.

    I want to stay with default permalinks but to add prefix /blog/ before only for the posts but for the pages to use pretty permalinks

  4. nikoza
    Member
    Posted 2 years ago #

    Hey guys,

    After searching and trying several things the solution end up being.

    Head over to general permalinks and add the blog prefix to your permalink structure. Then go to your plugin or functions.php file where you register the post type and add the following:

    'rewrite' => array('with_front' => false, 'slug' => 'your-slug').

    That will keep the custom post types under the domain. Remember to do the same for the custom taxonomies you register. Initally I thought it was the custom post type that was causing the problem but it was the taxonomy that was causing it.

    If you need anything else just ask!

  5. kevinrys
    Member
    Posted 1 year ago #

    nikoza's code works perfectly. just replace "your-slug" with the correct slug for the post type. thanks.

  6. brianj
    Member
    Posted 1 year ago #

    10 months later, I just searched this again haha

    Thanks very much for the solution Nikoza, works perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic