16

My Wordpress install has three post types: pages, posts, and portfolio. The current structure is as follows:

  • page: example.com/page-name,
  • post listing page: example.com/blog,
  • individual post: example.com/post-name,
  • portfolio listing page: example.com/portfolio,
  • individual portfolio post: example.com/portfolio/portfolio-name.

The thing I'd like to change is the individual post permalink, but nothing else. I'd like it to become example.com/blog/post-name.

I can't find documentation that shows how to make this change without affecting the other types.

EDIT : My current permalink structure is set up to be /%postname%/, and under Reading Settings, my posts page is set to Blog.

register_post_type('portfolio', array(  
'label' => 'Portfolio Items',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => array('slug' => 'portfolio'),
'with_front' => false,
'query_var' => false,
'has_archive' => true,
'exclude_from_search' => false,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
'taxonomies' => array('category','post_tag'),
'labels' => array (
    'name' => 'Portfolio Items',
    'singular_name' => 'Portfolio Item',
    'menu_name' => 'Portfolio Items',
    'add_new' => 'Add Portfolio Item',
    'add_new_item' => 'Add New Portfolio Item',
    'edit' => 'Edit',
    'edit_item' => 'Edit Portfolio Item',
    'new_item' => 'New Portfolio Item',
    'view' => 'View Portfolio Item',
    'view_item' => 'View Portfolio Item',
    'search_items' => 'Search Portfolio Items',
    'not_found' => 'No Portfolio Items Found',
    'not_found_in_trash' => 'No Portfolio Items Found in Trash',
    'parent' => 'Parent Portfolio Item',
)
));
trejder
  • 17,148
  • 27
  • 124
  • 216
frogg3862
  • 491
  • 1
  • 4
  • 19

1 Answers1

48

You simply have to set /blog/%postname%/ as your permalinks structure, this will not change your pages permalinks.

And to keep your portfolio permalinks, you should set with_front to false when you register this post type.

'with_front' => bool Should the permastruct be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true

EDIT 1 : You should probably flush Wordpress rewrite rules after that.

EDIT 2 : with_front param is a rewrite param :

'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
soju
  • 25,111
  • 3
  • 68
  • 70
  • Ok, so this mostly worked. Blog listing and individual blog pages are correct. The portfolio listing page and individual pages do not have the /blog/ which is correct. The remaining problem is this: When I go to my portfolio listing page, then click on one of the item's title-- to go to that item's page, it tries to go to example.com/blog/portfolio/porfolio-item-title Instead of going to the correct url of example.com/portfolio/portfolio-item-title – frogg3862 Mar 26 '13 at 15:24
  • Did you register your post type correctly as described in my answer ? You should also flush Wordpress rewrite rules. – soju Mar 26 '13 at 15:32
  • Yes, I had registered the post type how you described it. I just now flushed the rewrite rules. All of the blog pages are fine, but the portfolio is once again going to /blog/ – frogg3862 Mar 26 '13 at 15:37
  • Ah, that totally fixed it. My bad. Thank you so much! – frogg3862 Mar 26 '13 at 16:11
  • 3
    This works, but my `/author/name/` pages are only available as `/blog/author/name/` now.. How can I fix this? – Robbert Sep 09 '16 at 12:33
  • @soju – you're a life saver man... this is too obvious yet not so obvious. –  Feb 07 '17 at 07:51