Add understrap_body_attributes()

Function to display attributes for the body element. Attributes may be added via the filter `understrap_body_attributes`
This commit is contained in:
IanDelMar 2019-12-03 08:15:46 +01:00
parent 91cba1ccac
commit a2bbdb0eb7
2 changed files with 27 additions and 4 deletions

View File

@ -21,7 +21,7 @@ $container = get_theme_mod( 'understrap_container_type' );
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<body <?php body_class(); ?> <?php understrap_body_attributes(); ?>>
<?php do_action( 'wp_body_open' ); ?>
<div class="site" id="page">

View File

@ -45,7 +45,6 @@ if ( ! function_exists( 'understrap_posted_on' ) ) {
}
}
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
@ -83,7 +82,6 @@ if ( ! function_exists( 'understrap_entry_footer' ) ) {
}
}
/**
* Returns true if a blog has more than 1 category.
*
@ -113,7 +111,6 @@ if ( ! function_exists( 'understrap_categorized_blog' ) ) {
}
}
/**
* Flush out the transients used in understrap_categorized_blog.
*/
@ -129,3 +126,29 @@ if ( ! function_exists( 'understrap_category_transient_flusher' ) ) {
delete_transient( 'understrap_categories' );
}
}
if ( ! function_exists( 'understrap_body_attributes' ) ) {
/**
* Displays the attributes for the body element.
*/
function understrap_body_attributes() {
/**
* Filters the body attributes.
*
* @param array $atts An associative array of attributes.
*/
$atts = array_unique( apply_filters( 'understrap_body_attributes', $atts = array() ) );
if ( ! is_array( $atts ) || empty( $atts ) ) {
return;
}
$attributes = '';
foreach ( $atts as $name => $value ) {
if ( $value ) {
$attributes .= sanitize_key( $name ) . '="' . esc_attr( $value ) . '" ';
} else {
$attributes .= sanitize_key( $name ) . ' ';
}
}
echo trim( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput
}
}