Styles: Add helper class to hide page title on pages in main menu

This commit is contained in:
Kelly Dwan 2024-08-29 18:22:37 -04:00
parent 8df86334e3
commit 4e06badef3
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
2 changed files with 32 additions and 0 deletions

View file

@ -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;
}

View file

@ -19,6 +19,13 @@
--wp--custom--form--border--width: 0;
}
/* Hide the post title on search pages, or if it is in the main navigation. */
body.search .wp-block-wporg-local-navigation-bar .wp-block-post-title,
body.is-page-in-menu .wp-block-wporg-local-navigation-bar .wp-block-post-title {
display: none;
}
/* Style the group blocks inside a template list. */
.wp-block-post:where(li.type-5ftf_pledge) {
> .wp-block-group {