$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Change the Slug of Post Type post to baseurlpost%postname%|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Change the Slug of Post Type post to baseurlpost%postname%

matteradmin9PV0评论

I have been searching around but i cant anywhere find the answer to my question: How to change the post slug for all posts (and the categories etc.). Without affecting other pages/ custom post urls. So i want to change the url for default posts from:

url/postname > url/news/postname

Without affecting page urls and or custom post type urls. The only method i have so far found that achieved what i was looking for was:

/

add_action( 'init', 'my_new_default_post_type', 1 );
function my_new_default_post_type() {

register_post_type( 'post', array(
    'labels' => array(
        'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
    ),
    'public'  => true,
    '_builtin' => false, 
    '_edit_link' => 'post.php?post=%d', 
    'capability_type' => 'post',
    'map_meta_cap' => true,
    'hierarchical' => false,
    'rewrite' => array( 'slug' => 'post' ),
    'query_var' => false,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
) );
}

By re-registering the post type. But this also has the side effect that it creates a second menu item on the left side of the admin panel called post. They both contain the same data though.

Hopefully somebody has an answer to this problem.

I have been searching around but i cant anywhere find the answer to my question: How to change the post slug for all posts (and the categories etc.). Without affecting other pages/ custom post urls. So i want to change the url for default posts from:

url/postname > url/news/postname

Without affecting page urls and or custom post type urls. The only method i have so far found that achieved what i was looking for was:

http://wordimpress/how-to-add-a-custom-permalink-structure-for-only-the-wordpress-default-post-type/

add_action( 'init', 'my_new_default_post_type', 1 );
function my_new_default_post_type() {

register_post_type( 'post', array(
    'labels' => array(
        'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
    ),
    'public'  => true,
    '_builtin' => false, 
    '_edit_link' => 'post.php?post=%d', 
    'capability_type' => 'post',
    'map_meta_cap' => true,
    'hierarchical' => false,
    'rewrite' => array( 'slug' => 'post' ),
    'query_var' => false,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
) );
}

By re-registering the post type. But this also has the side effect that it creates a second menu item on the left side of the admin panel called post. They both contain the same data though.

Hopefully somebody has an answer to this problem.

Share Improve this question asked Jul 1, 2013 at 13:12 N.SchipperN.Schipper 2151 gold badge3 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 10

There is no need to reregister the default post post type. You can just add a prefix to the permalink structure using the Permalinks settings, found under the main Settings menu in your WordPress administration panel:

Post a comment

comment list (0)

  1. No comments so far