我在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
中我应该怎么做?覆盖以上内容还是什么?
答案 0 :(得分:1)
为此,您首先需要删除父主题应用的过滤器,然后再次在子主题中对其进行定义,如下所示:
儿童主题功能。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;
}
答案 1 :(得分:0)
子主题函数.php在父主题函数.php之前加载,因此,如果父主题函数具有复选if ( ! function_exists() )
,则可以在子函数.php中用相同的函数名称覆盖它。