wc_list_pages function refactored

This commit is contained in:
Khan M Rashedun-Naby 2018-05-15 08:08:18 +06:00
parent 85eaec1a8a
commit f7baef9938
1 changed files with 14 additions and 14 deletions

View File

@ -204,7 +204,10 @@ add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2 );
* @return string * @return string
*/ */
function wc_list_pages( $pages ) { function wc_list_pages( $pages ) {
if ( is_woocommerce() ) { if ( ! is_woocommerce() ) {
return $pages;
}
// Remove current_page_parent class from any item. // Remove current_page_parent class from any item.
$pages = str_replace( 'current_page_parent', '', $pages ); $pages = str_replace( 'current_page_parent', '', $pages );
// Find shop_page_id through woocommerce options. // Find shop_page_id through woocommerce options.
@ -212,13 +215,10 @@ function wc_list_pages( $pages ) {
if ( is_shop() ) { if ( is_shop() ) {
// Add current_page_item class to shop page. // Add current_page_item class to shop page.
$pages = str_replace( $shop_page, $shop_page . ' current_page_item', $pages ); return str_replace( $shop_page, $shop_page . ' current_page_item', $pages );
} else {
// Add current_page_parent class to shop page.
$pages = str_replace( $shop_page, $shop_page . ' current_page_parent', $pages );
}
} }
return $pages; // Add current_page_parent class to shop page.
return str_replace( $shop_page, $shop_page . ' current_page_parent', $pages );
} }
add_filter( 'wp_list_pages', 'wc_list_pages' ); add_filter( 'wp_list_pages', 'wc_list_pages' );