Archived topic
How do I remove Page Header Settings from selected CPT's and Taxonomies?
5 replies · Started by ninjajay on December 14, 2017
I'm just wondering if there is a way that I can disable the page header settings from appearing on selected custom taxonomy and post type admin pages?
In another plugin I use (Restrict Content Pro) I can use a filter to stop the plugin's settings from appearing selected taxonomies. The way it works in RCP is the filter is passed an array of taxonomies, from there I just remove the taxonomies from the array where I don't want the settings to appear.
Here is what it looks like in RCP:
function exclude_taxonomies_from_rcp( $taxonomies ) {
return array_diff( $taxonomies, [ 'team', 'season', 'opposition', 'sponsorship-level' ] ) ;
}
add_filter( 'rcp_get_restricted_taxonomies', 'exclude_taxonomies_from_rcp', 20 );
Hey Jay,
Just so I understand, you want to remove the Page Header select dropdown from inside specific taxonomy edit/add pages and from the "Layout" metabox?
Let me know :)
Yes that’s exactly right, custom taxonomies and post types. The only reason I enabled the page header functionality on this site is because I wanted control over the featured image placement.
Featured images are all handled by the Blog module now in Customize > Layout > Blog.
Page Headers only apply when there's page header content involved.
Either way, you should be able to do this:
add_action( 'init', 'tu_remove_page_header_tax', 20 );
function tu_remove_page_header_tax() {
$taxonomies = array( 'one-taxonomy-id', 'another-id' );
foreach ( $taxonomies as $taxonomy ) {
remove_action( $taxonomy . '_add_form_fields', 'generate_page_header_tax_new_ph_field' );
remove_action( $taxonomy . '_edit_form_fields', 'generate_page_header_tax_edit_ph_field' );
remove_action( 'edit_' . $taxonomy, 'generate_page_header_tax_save_ph' );
remove_action( 'create_' . $taxonomy, 'generate_page_header_tax_save_ph' );
}
$post_types = array( 'one-post-type-id', 'another-one' );
if ( in_array( get_post_type(), $post_types ) ) {
remove_action( 'generate_layout_meta_box_menu_item', 'generate_premium_page_header_menu_item' );
}
}
Thanks so much for the support Tom I've disabled the page header add-on. But, it's great to have the code, I can think of multiple use cases where I'd like to disable the page header settings on CPT's and Taxonomies.
Glad I could help! :)