Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'no-content' and 'has-banner' classes to BODY. #244

Open
ghost opened this issue Jan 26, 2021 · 1 comment
Open

Add 'no-content' and 'has-banner' classes to BODY. #244

ghost opened this issue Jan 26, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 26, 2021

There are many instances for the purposes of design/styles (especially when using BULP) when it becomes necessary to identify if the content editor is empty or if there is a Banner being used on the page. This function would add classes to the body if either is true.

 * Add 'no-banner' and/or 'has-bu-banner' class to BODY to the page.
 *
 * @param string $classes The class or classes to be added to the body.
 * @param number $_post The post ID.
 * @param string $content The post content from the editor.
 * @param bool $banner_visible Check if there is a BU Banner.
 * @return string $classes The class or classes to be added to the body.
 */
function responsi_banner_content_class( $classes ) {
	// Get post ID. Return if none.
	$_post = get_post();

	if ( empty( $_post ) ) {
		return;
	}

	// Get Post Content from content editor.
	$content = $_post->post_content;

	// If no content, add class to Body.
	if ( empty( $content ) ) {
		$classes[] = 'no-content';
	}

	// Check that BU Banners is installed and if there is a banner on the current page.
	$banner_visible = false;
	if ( function_exists( 'bu_has_banner' ) ) {
		$banner_visible = bu_has_banner();
	}

	// If there is a banner, add class to Body.
	if ( $banner_visible ) {
		$classes[] = 'has-bu-banner';
	}

	// Add $classes array to body.
	return $classes;
}
add_filter( 'body_class', 'responsi_banner_content_class' );```
@acketon
Copy link
Member

acketon commented Sep 15, 2022

this should probably be done in two repos: bu-banners and bu-landing pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants