From a2bbdb0eb751db0c05641e51e913477494830d33 Mon Sep 17 00:00:00 2001
From: IanDelMar <42134098+IanDelMar@users.noreply.github.com>
Date: Tue, 3 Dec 2019 08:15:46 +0100
Subject: [PATCH] Add understrap_body_attributes()
Function to display attributes for the body element. Attributes may be added via the filter `understrap_body_attributes`
---
header.php | 2 +-
inc/template-tags.php | 29 ++++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/header.php b/header.php
index f19f527..a6dcb6e 100644
--- a/header.php
+++ b/header.php
@@ -21,7 +21,7 @@ $container = get_theme_mod( 'understrap_container_type' );
-
>
+ >
diff --git a/inc/template-tags.php b/inc/template-tags.php
index 2beb880..43700a4 100644
--- a/inc/template-tags.php
+++ b/inc/template-tags.php
@@ -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
+ }
+}