Remove sub menu items - wordpress

I want to remove a few sub menu items from the admin menu in WordPress. I have found the following which can remove certain sub menu items...
add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu() {
$page = remove_submenu_page( 'themes.php', 'widgets.php' );
}
...but what if it is not a standard php such as "themes.php?page=custom-header" that I would like removed.

This worked for me. Thanks to Ravi for pointing me in the right direction.
add_action( 'init', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
// remove products->categories
register_taxonomy('product_cat',
'woocommerce_taxonomy_objects_product_cat', array('show_ui' => false)
);
// remove products->tags
register_taxonomy('product_tag',
'woocommerce_taxonomy_objects_product_tag', array('show_ui' => false)
);
// remove products->shipping classes
register_taxonomy('product_shipping_class',
'woocommerce_taxonomy_objects_product_shipping_class', array('show_ui' => false)
);
}
add_action( 'admin_menu', 'remove_submenu_pages', 999 );
function remove_submenu_pages() {
// remove products->attributes
remove_submenu_page( 'edit.php?post_type=product', 'woocommerce_attributes');
}

Add code in your function.php
Remove "themes.php?page=custom-header" option using this code.
function remove_twentyeleven_options() {
remove_custom_image_header();
}
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );

I would like to share, that's how you can remove woocommerce submenu's
Product Attributes
Product Shipping Class
--
add_action( 'admin_menu', 'remove_taxonomy_menu_pages', 999 );
function remove_taxonomy_menu_pages() {
remove_submenu_page( 'edit.php?post_type=product', 'product_attributes' );
remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product');
}

Related

How to remove gutenberg_render_title_tag from theme function file?

I have try remove action but not working.
add_action( 'wp_loaded', 'remove_my_action' );
function remove_my_action() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', -1 );
}
or
add_action( 'init', 'remove_my_action' );
function remove_my_action() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', -1 );
}
i am using yoast plugin. Yoast plugin also using remove action https://github.com/Yoast/wordpress-seo/blob/trunk/src/integrations/front-end-integration.php#L220 but it's not working. Still tag coming two time. i wants to remove gutenberg title tag.
I got the solution for this.
add_action( 'wp', 'remove_default_guten_title' );
function remove_default_guten_title() {
foreach ( gutenberg_get_template_type_slugs() as $template_type ) {
add_filter( str_replace( '-', '', $template_type ) . '_template', 'remove_default_title', 21, 3 );
}
}
function remove_default_title() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', 1 );
return gutenberg_dir_path() . 'lib/template-canvas.php';
}

Wordpress Admin Menu, display an other name for the top level

I am trying to add a different menu title. Like "Goto" should be "More" but if you click on it it should still go to the first.
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('More', 'More', 'manage_options', 'my-menu', 'edit.php?post_type=goto' );
add_submenu_page('my-menu', 'Goto', 'Goto', 'manage_options', 'edit.php?post_type=goto' );
add_submenu_page('my-menu', 'Gallerys', 'Gallerys', 'manage_options', 'edit.php?post_type=join' );
}
Add the follows code snippet in your active theme's functions.php to achieve the above -
add_action( 'admin_menu', 'fix_admin_menu', 999 );
function fix_admin_menu(){
global $submenu;
if ( ! isset( $submenu['my-menu'] ) ) {
return;
}
unset( $submenu['my-menu'][0] );
}

How to remove sub menu page in WP admin which uses admin.php and a query string

How do I remove a sub-menu with link
http://vagrant.local/wp/wp-admin/admin.php?page=home_settings_page ?
I tried remove_submenu_page( 'admin.php', 'yrc_home_settings_page' );
but that didn't work.
Edit
function remove_menu_pages_for_fuel_surcharge_editor() {
if(current_user_can('fuel-surcharge-editor')) {
remove_menu_page('tools.php');
remove_menu_page('options-general.php');
remove_menu_page('edit.php?post_type=show_event');
remove_menu_page('jetpack');
remove_submenu_page( 'admin.php', 'yrc_home_settings_page' );
}
}
add_action('admin_menu', 'remove_menu_pages_for_fuel_surcharge_editor', 999);
I also tried which didn't work either.
add_action('admin_init', 'remove_menu_pages_for_fuel_surcharge_editor', 999);
Screenshot:
I think you will need to add the function to a hook. Try something like:
function remove_submenu() {
remove_submenu_page( 'admin.php', 'yrc_home_settings_page' );
}
add_action( 'admin_menu', 'remove_submenu', 999 );
I'm not entirely sure if the second parameter in your function is correct.

rewrite url with custom plugin with permalink

I have developed plugin and uses shortcode to display.
So, there is two type of items to display like
if get title in url, display single item and if not all items so i have added into if else in condition.
So for that title, i have passed
add_query_arg( array('title' =>sanitize_title($data->get_title())), get_permalink($post_id) );
now url is generated by this is domain.com/post-slug/?title=nameoftitle
but i want to url like domain.com/post-slug/nameoftitle
I have tried following code but not working
function update_rewrite_rules() {
add_rewrite_tag( '%title%', '([^/]*)' );
add_rewrite_rule(
$newVarRegex,
'index.php?pagename=$matches[1]&title=$matches[2]',
'top'
);
}
add_action( 'init', 'update_rewrite_rules' );
but its not working
I got solution of it. working code is:
function js_update_rewrite_rules() {
add_rewrite_tag( '%title%', '([^/]*)' );
$rewrite_rules = get_option( 'rewrite_rules' );
$newVarRegex = '^([^/]*)/title/([^/]*)/?';
// check if the rule exists
if ( !isset( $rewrite_rules[$newVarRegex] ) ) {
add_rewrite_rule(
$newVarRegex,
'index.php?pagename=$matches[1]&title=$matches[2]',
'top'
);
flush_rewrite_rules();
}
}
function js_on_activation() {
js_update_rewrite_rules();
}
register_activation_hook( __FILE__, 'js_on_activation' );
function js_on_init() {
js_update_rewrite_rules();
}
add_action( 'init', 'js_on_init' );

Wordpress remove from admin bar menu

I tried to remove User right section but with no luck any help ? WP version 3.8
This code not working ...
add_action( 'init', 'remove_user_account_menu' );
function remove_user_account_menu() {
remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 );
remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 );
}
The following will do the trick:
add_action( 'wp_before_admin_bar_render', 'so27304117_before_admin_bar_render' );
function so27304117_before_admin_bar_render()
{
global $wp_admin_bar;
$wp_admin_bar->remove_menu('my-account');
}
Dive into the admin toolbar API.

Resources