mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-10 04:25:44 +03:00
Styles: Add helper class to hide page title on pages in main menu
This commit is contained in:
parent
8df86334e3
commit
4e06badef3
2 changed files with 32 additions and 0 deletions
|
@ -20,6 +20,7 @@ add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
|
|||
add_filter( 'the_content', __NAMESPACE__ . '\inject_pledge_content', 1 );
|
||||
add_filter( 'get_the_excerpt', __NAMESPACE__ . '\inject_pledge_content', 1 );
|
||||
add_filter( 'search_template_hierarchy', __NAMESPACE__ . '\use_archive_template' );
|
||||
add_filter( 'body_class', __NAMESPACE__ . '\add_body_class' );
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
|
@ -73,3 +74,27 @@ function use_archive_template( $templates ) {
|
|||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a class to body when the current page is in the menu.
|
||||
*
|
||||
* @param string[] $classes An array of body class names.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function add_body_class( $classes ) {
|
||||
global $wp;
|
||||
// Get the main menu using the hooked function.
|
||||
$menus = Block_Config\add_site_navigation_menus( [] );
|
||||
$slug = $wp->request;
|
||||
$has_page = array_filter(
|
||||
$menus['main'],
|
||||
function ( $item ) use ( $slug ) {
|
||||
return trim( $item['url'], '/' ) === $slug;
|
||||
}
|
||||
);
|
||||
if ( ! empty( $has_page ) ) {
|
||||
$classes[] = 'is-page-in-menu';
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue