简体   繁体   中英

Wordpress Overwrite add_menu_page from Child theme?

How to Overwrite the add_menu_page function from Child Theme. my code is below

add_action('admin_menu', 'goal_settings_page');
function goal_settings_page() {
add_menu_page(
          __('my menu'), 
          __('my menu'), 
          'manage_options', 'settings', 
          'sake_settings_page');
}

function sake_settings_page() {
    // parent theme code here
}

I want to Overwrite sake_settings_page function from Child theme How to overwrite that function please help.

Thanks

First, Add/update you function to your parent theme like below

if ( ! function_exists ( 'sake_settings_page' ) )  {
    function sake_settings_page() {
        // Contents of your function here.
    } 
}

Then put the same function(which you want to override) to your child theme.

Note : if you enclose the functions in your parent theme in a conditional tag like this, WordPress will check if there is a function with the same name in your child theme that's already been run, and if that's the case it won't run the function from the parent theme.

WordPress will run the function in the child theme first, and when it comes to the one in the parent theme, it'll check if it already exists and because it does, it won't run it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM