wc_list_pages( string $pages )

Fix active class in wp_list_pages for shop page.


Description Description

See details in https://github.com/woocommerce/woocommerce/issues/177.


Parameters Parameters

$pages

(Required) Pages list.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-page-functions.php

function wc_list_pages( $pages ) {
	if ( ! is_woocommerce() ) {
		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 );
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.