wc_list_pages function refactored
This commit is contained in:
parent
85eaec1a8a
commit
f7baef9938
|
@ -204,21 +204,21 @@ add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2 );
|
|||
* @return string
|
||||
*/
|
||||
function wc_list_pages( $pages ) {
|
||||
if ( is_woocommerce() ) {
|
||||
// Remove current_page_parent class from any item.
|
||||
$pages = str_replace( 'current_page_parent', '', $pages );
|
||||
// Find shop_page_id through woocommerce options.
|
||||
$shop_page = 'page-item-' . wc_get_page_id( 'shop' );
|
||||
|
||||
if ( is_shop() ) {
|
||||
// Add current_page_item class to shop page.
|
||||
$pages = 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 );
|
||||
}
|
||||
if ( ! is_woocommerce() ) {
|
||||
return $pages;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
// Remove current_page_parent class from any item.
|
||||
$pages = str_replace( 'current_page_parent', '', $pages );
|
||||
// Find shop_page_id through woocommerce options.
|
||||
$shop_page = 'page-item-' . wc_get_page_id( 'shop' );
|
||||
|
||||
if ( is_shop() ) {
|
||||
// Add current_page_item class to shop page.
|
||||
return str_replace( $shop_page, $shop_page . ' current_page_item', $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' );
|
||||
|
|
Loading…
Reference in New Issue