Default post type doesn't display in url

My site currently has an opinions page which displays opinions posts (/opinions/).

The post pages are only showing as /post-title/ when I need /opinions/post-title/.

Code below, changes the default post type to "opinions".

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

What do I need to add so that it constructs the url as /opinions/post-title/?


Changing arguments for a post type "on the fly" by changing the global at some random point in time is below ideal. When you look at register_post_type() there is the register_post_type_args filter.

Example on how to use it as a small (mu-)plugin:

 * Plugin Name: Change Post Type arguments for Post Type X
add_filter( 'plugins_loaded', function() {

    add_filter( 'register_post_type_args', function( Array $args, $post_type ) {
        // Change nothing for all other post types
        if ( 'your_post_type' !== $post_type )
            return $args;

        $args['rewrite'] => [
            'with_front' => true,
            'slug'       => 'opinions',

        return $args;
    }, 20, 2 );
} );

In above example, the post type gets a /opinions "front" prepended. Example resulting Url:

To adjust the labels, use the labels array that you will find in above link and in all examples below (plus changing help tabs, update messages, etc.).

Your admin menu slugs and labels will adjust accordingly by themselves, fed by the labels arguments you provided.

Category: posts Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.259 (s). 12 q(s)