문제

I have change the Posts to News, which is the default post type of wordpress. But I want to change the url also. Means when I hover on the menu News, The url is like http://www.example.com/blog/

I want to change to http://www.example.com/News/. Can I change to the code which is written for change the default post type name (Post to News).

I used the code for change the name

function revcon_change_post_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'News';
    $submenu['edit.php'][5][0] = 'News';
    $submenu['edit.php'][10][0] = 'Add News';
    $submenu['edit.php'][16][0] = 'News Tags';
    echo '';
}
function revcon_change_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'News';
    $labels->singular_name = 'News';
    $labels->add_new = 'Add News';
    $labels->add_new_item = 'Add News';
    $labels->edit_item = 'Edit News';
    $labels->new_item = 'News';
    $labels->view_item = 'View News';
    $labels->search_items = 'Search News';
    $labels->not_found = 'No News found';
    $labels->not_found_in_trash = 'No News found in Trash';
    $labels->all_items = 'All News';
    $labels->menu_name = 'News';
    $labels->name_admin_bar = 'News';
}

add_action( 'admin_menu', 'revcon_change_post_label' );
add_action( 'init', 'revcon_change_post_object' );
도움이 되었습니까?

해결책

What you are trying to achieve can be handled in a more "Wordpressy" and sophisticated way using Custom Post Types (a.k.a CPT's). You have complete control over the Custom Post Type you create including the URL to display.

If you don't want to code the CPT yourself there are plugins you can try for instance: https://wordpress.org/plugins/custom-post-type-ui/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top