1

I want to add /post/ to the default post post type url. I have tried it by register the 'post' post type as follows:

function fdm_register_post_types() {

   // Get post post type object
   $object = get_post_type_object( 'post' );

   // Set rewrite argument
   $object->rewrite = array( 'slug' => 'post', 'with_front' => false );

   // Reregister post type
   register_post_type( 'post', $object );

}
add_action( 'init', 'fdm_register_post_types' );

No success.

According to this Stack post, you need to set the permalink structure (under settings -> permalinks) to /post/%postname%/ and set other post types rewrite argument to:

'rewrite' => array('slug' => 'post_type_name', 'with_front' => false),

This works fine, but when I visit my author pages now. I can only visit them like /post/author/name/ and not /author/name/.

Is there a better solution for editing the 'post' post type or should I change something in the author functionality?

1 Answer 1

1

Using the permalink settings to configure your post permalinks, then modifying the author permalinks seems like the way to go.

I set up the permalink rules like this:

/post/%postname%/

Then used this code to modify the author permalinks (source):

// change base of author pages- need to save permalinks to take effect
function wpse82004_change_author_permalink(){
    global $wp_rewrite;
    $wp_rewrite->author_base = 'author';
    $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '/%author%';
}
add_action( 'init','wpse82004_change_author_permalink' );

Remember to save permalinks afterwards.

4
  • Thanks for your answer. This seems to work, but do you know why this can't be done by editing the 'post' post type rewrite arguments?
    – Robbert
    Sep 13, 2016 at 14:03
  • Glad it worked for you (I tested it and it worked for me too.) Author permalinks are not post post type permalinks; they are handled independently and there is no UI available to implement the code in the answer. Sep 13, 2016 at 14:08
  • No I mean, why am I not able to edit the post post type base (without doing it under settings -> permalinks), so that I not even need to edit the author base.
    – Robbert
    Sep 13, 2016 at 14:16
  • Pretty sure you'd have to modify the author base to achieve the configuration you're after regardless. The post permalink structure is stored under the permalink_structure option and that would need to be taken into account to make sure you're not fighting that when changing the settings programmatically. Sep 13, 2016 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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