user1359872
user1359872

Reputation:

Remove admin menu item from child theme

The parent theme registers a custom post type called risen_event. I have decided to use another calendar plugin thus want to remove this admin menu item from the user.

Inside the child theme I tried this function but it did not work

if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type( $post_type ) {
    global $wp_post_types;
    if ( isset( $wp_post_types[ $post_type ] ) ) {
        unset( $wp_post_types[ $post_type ] );
        return true;
    }
    return false;
}
endif;

Upvotes: 0

Views: 1950

Answers (2)

AndyWarren
AndyWarren

Reputation: 2012

Put this in your child theme's functions.php file if all you want to do is hide the admin menu item:

function hide_menu_items() {
    remove_menu_page( 'edit.php?post_type=your_post_type_url' );
}
add_action( 'admin_menu', 'hide_menu_items' );

Hover over the admin menu item and look at the URL to get the correct one to use in the function. This will not deregister the post type, just hide the admin menu item. That leaves the post type in place in case you ever decided you want to use it in the future.

Upvotes: 5

brasofilo
brasofilo

Reputation: 26065

From the code you posted, looks like you're not calling the function.

But the call cannot be direct, you gotta wrap it inside an action, like:

add_action( 'init', 'so_13666286_init', 11 );

function so_13666286_init()
{
    unregister_post_type( 'risen_event' );
}

Or using other technique:

add_action( 'after_setup_theme','so_13666286_remove_action', 100 );

function so_13666286_remove_action() 
{   
    remove_action( 'init', 'the_init_function_that_creates_the_cpt' );    
}

Reference: Deregister custom post types.

Upvotes: 0

Related Questions