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 1/2] 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 + } +} From 7a63872671d33356265636f4ede0dc0678543a89 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Tue, 3 Dec 2019 08:19:45 +0100 Subject: [PATCH 2/2] Move schema markup to body element Removes schema markup from the div#wrapper-navbar element. Re-adds the schema markup on the body element via filter. --- header.php | 2 +- inc/extras.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/header.php b/header.php index a6dcb6e..a6c0f01 100644 --- a/header.php +++ b/header.php @@ -26,7 +26,7 @@ $container = get_theme_mod( 'understrap_container_type' );
-
+
diff --git a/inc/extras.php b/inc/extras.php index e80198f..5943746 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -133,3 +133,18 @@ if ( ! function_exists( 'understrap_mobile_web_app_meta' ) ) { } } add_action( 'wp_head', 'understrap_mobile_web_app_meta' ); + +if ( ! function_exists( 'understrap_default_body_attributes' ) ) { + /** + * Adds schema markup to the body element. + * + * @param array $atts An associative array of attributes. + * @return array + */ + function understrap_default_body_attributes( $atts ) { + $atts['itemscope'] = ''; + $atts['itemtype'] = 'http://schema.org/WebSite'; + return $atts; + } +} +add_filter( 'understrap_body_attributes', 'understrap_default_body_attributes' );