• Hi

    I have a custom post type – works – being declared by my theme, as follows –

    if ( ! function_exists( 'md_works' ) ) {
    	function md_works() {
    
    		$labels = array(
    			'name' => _x( "Works", "Post type name", 'dronetv' ),
    			'singular_name' => _x( "Works", "Post type singular name", 'dronetv' ),
    			'add_new' => _x( "Add New Project", "work item", 'dronetv' ),
    			'add_new_item' => __( "Add New Project", 'dronetv' ),
    			'edit_item' => __( "Edit Project", 'dronetv' ),
    			'new_item' => __( "New Project", 'dronetv' ),
    			'view_item' => __( "View Project", 'dronetv' ),
    			'search_items' => __( "Search Project", 'dronetv' ),
    			'not_found' =>  __( "Not found", 'dronetv' ),
    			'not_found_in_trash' => __( "Trash is empty", 'dronetv' ),
    			'parent_item_colon' => ''
    		);
    
    		register_post_type( 'works' , array(
    			'label'=>_x('Works','Type','dronetv'),
    			'description'=>__('Special type of post for creating project','dronetv'),
    			'labels' => $labels,
    			'public' => true,
    			'menu_position' => 5,
    			'show_ui' => true,
    			'show_in_menu' => true,
    			'publicly_queryable' => true,
    			'exclude_from_search' => true,
    			'query_var' => true,
    			'menu_icon'=>get_template_directory_uri() . '/images/portfolio_icon.png',
    			'rewrite' => true,
    			'capability_type' => 'post',
    			'hierarchical' => false,
    			'supports' => array( 'title', 'editor','thumbnail')
    			)
    		  ); 
    
    		//$wp_rewrite->flush_rules();
    		flush_rewrite_rules();
    	}
    }

    I want to change the slug from ‘works’ to something else. I know I can do this by changing the ‘rewrite => true’ line of code to ‘rewrite => array( ‘slug’ => ‘my-new-name’ )’. However my code will be lost when the theme is updated.

    I have a child theme activated. My question is whether there a way to achieve this change of slug by adding some sort of filter function in the child theme functions.php file?

    Any advice appreciated.

    Johnny

  • The topic ‘Change Custom Post Type Slug’ is closed to new replies.