如何在子主题上编辑函数?

我在function.php的主要主题上具有此函数:

if(!function_exists('eagle_booking_append_booking_button_menu') && eagle_booking_get_option('eagle_booking_header_button')):

    add_filter( 'wp_nav_menu_items', 'eagle_booking_append_booking_button_menu', 12, 2 );

    function eagle_booking_append_booking_button_menu ( $items, $args ) {

        // BUTTON ACTION BASED ON BOOKING SYSTEM
        if (eagle_booking_get_option('booking_type') == 'builtin' ) {
          $eagle_booking_button_action  = eagle_booking_search_page();

        } elseif (eagle_booking_get_option('booking_type') == 'custom') {
          $eagle_booking_button_action = eagle_booking_get_option('booking_type_custom_action');

        } elseif (eagle_booking_get_option('booking_type') == 'booking') {
          $eagle_booking_button_action = eagle_booking_get_option('booking_type_booking_action');

        } elseif (eagle_booking_get_option('booking_type') == 'airbnb') {
          $eagle_booking_button_action = eagle_booking_get_option('booking_type_airbnb_action');

        } elseif (eagle_booking_get_option('booking_type') == 'tripadvisor') {
          $eagle_booking_button_action = eagle_booking_get_option('booking_type_tripadvisor_action');
        }

        if ((eagle_booking_get_option('eagle_booking_header_button')) && ( $args->theme_location == 'zante_main_menu' )) {
            $items .= '<li class="menu_button"><a href="'.$eagle_booking_button_action.'" class="button"><i class="fa fa-calendar"></i>'.esc_html__('BOOK ONLINE', 'eagle-booking').'</a></li>';
        }

        return $items;
    }

endif;

我想编辑函数的最后一部分, 例如:

if ((eagle_booking_get_option('eagle_booking_header_button')) && ( $args->theme_location == 'zante_main_menu' )) {
    $mdpLinkButton = "/contact-us/";
    $items .= '<li class="menu_button"><a href="'.$mdpLinkButton.'" class="button"><i class="fa fa-calendar"></i>'.esc_html__('CONTACT US', 'eagle-booking').'</a></li>';
}

我做了自定义主题。但是我应该在那个function.php中做什么?覆盖上面还是什么?


#1


为此, 你需要删除父主题应用的过滤器, 然后在子主题中再次定义它, 如下所示:

子主题functions.php

add_action( 'init', 'remove_my_action');
function remove_my_action() {
    remove_filter( 'wp_nav_menu_items', 'eagle_booking_append_booking_button_menu', 12 );
}

add_filter( 'wp_nav_menu_items', 'child_eagle_booking_append_booking_button_menu', 12, 2 );

function child_eagle_booking_append_booking_button_menu ( $items, $args ) {

    // BUTTON ACTION BASED ON BOOKING SYSTEM
    if (eagle_booking_get_option('booking_type') == 'builtin' ) {
      $eagle_booking_button_action  = eagle_booking_search_page();

    } elseif (eagle_booking_get_option('booking_type') == 'custom') {
      $eagle_booking_button_action = eagle_booking_get_option('booking_type_custom_action');

    } elseif (eagle_booking_get_option('booking_type') == 'booking') {
      $eagle_booking_button_action = eagle_booking_get_option('booking_type_booking_action');

    } elseif (eagle_booking_get_option('booking_type') == 'airbnb') {
      $eagle_booking_button_action = eagle_booking_get_option('booking_type_airbnb_action');

    } elseif (eagle_booking_get_option('booking_type') == 'tripadvisor') {
      $eagle_booking_button_action = eagle_booking_get_option('booking_type_tripadvisor_action');
    }

    if ((eagle_booking_get_option('eagle_booking_header_button')) && ( $args->theme_location == 'zante_main_menu' )) {
$mdpLinkButton = "/contact-us/";
        $items .= '<li class="menu_button"><a href="'.$mdpLinkButton.'" class="button"><i class="fa fa-calendar"></i>'.esc_html__('CONTACT US', 'eagle-booking').'</a></li>';
    }

    return $items;
}

#2


子主题functions.php在父主题functions.php之前加载, 因此如果父主题函数具有检查(!function_exists()), 则可以在子functions.php中使用相同的函数名称覆盖它。

来源:

https://www.srcmini02.com/63277.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37664.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?