Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add custom ID to div.site-inner with filter
Tagged: add ids, genesis_markup_{context} filter, genesis_markup_{context}_output filter, genesis_markup(), genesis_structural_wrap-{context} filter
- This topic has 3 replies, 2 voices, and was last updated 9 years, 9 months ago by saxisme.
-
AuthorPosts
-
March 4, 2014 at 5:01 pm #93438aaroncMember
Hello all,
I'd like to add a custom ID to the
<div class=".site-inner">
of my site, but am having trouble implementing the filter properly.I've found the
genesis_markup_{context}
and thegenesis_markup_{context}_output
filters in markup.php and attempted filtering using this code in my child theme's functions.php with no success:function ac_custom_site_inner( $tag, $args ) { $args['html5'] = '<div id="test" %s>'; return $tag; } add_filter('genesis_markup_site-inner_output', 'ac_custom_site_inner' );
Any help is greatly appreciated.
Thanks,
Aaron----
P.S. I've included the
genesis_markup()
(from markup.php) below for reference:/** * Output markup conditionally. * * Supported keys for <code>$args</code> are: * * - <code>html5</code> (<code>sprintf()</code> pattern markup), * - <code>xhtml</code> (XHTML markup), * - <code>context</code> (name of context), * - <code>echo</code> (default is true). * * If the child theme supports HTML5, then this function will output the <code>html5</code> value, with a call to <code>genesis_attr()</code> * with the same context added in. Otherwise, it will output the <code>xhtml</code> value. * * Applies a <code>genesis_markup_{context}</code> filter early to allow shortcutting the function. * * Applies a <code>genesis_markup_{context}_output</code> filter at the end. * * @since 1.9.0 * * @uses genesis_html5() Check for HTML5 support. * @uses genesis_attr() Contextual attributes. * * @param array $args Array of arguments. * * @return string Markup. */ function genesis_markup( $args = array() ) { $defaults = array( 'html5' => '', 'xhtml' => '', 'context' => '', 'echo' => true, ); $args = wp_parse_args( $args, $defaults ); //* Short circuit filter $pre = apply_filters( 'genesis_markup_' . $args['context'], false, $args ); if ( false !== $pre ) return $pre; if ( ! $args['html5'] || ! $args['xhtml'] ) return ''; //* If HTML5, return HTML5 tag. Maybe add attributes. Else XHTML. if ( genesis_html5() ) { $tag = $args['context'] ? sprintf( $args['html5'], genesis_attr( $args['context'] ) ) : $args['html5']; } else { $tag = $args['xhtml']; } //* Contextual filter $tag = $args['context'] ? apply_filters( 'genesis_markup_' . $args['context'] . '_output', $tag, $args ) : $tag; if ( $args['echo'] ) echo $tag; else return $tag; }
March 4, 2014 at 7:55 pm #93455aaroncMemberI've also found the
genesis_structural_wrap-{context}
filter in layout.php on line 494.I tried filtering it using the following code in my child functions.php with no success:
function ac_custom_site_inner_output( $output, $original_output ) { switch ( $original_output ) { case 'open': $output = sprintf( '<div id="test" %s>', genesis_attr( 'structural-wrap' ) ); break; case 'close': $output = '</div>'; break; } return $output; } add_filter('genesis_structural_wrap-site-inner', 'ac_custom_site_inner_output');
Again, any help is greatly appreciated.
Thanks,
Aaron---
P.S. I've included the genesis_structural_wrap() function below for convenience:
/** * Potentially echo or return a structural wrap div. * * A check is made to see if the <code>$context</code> is in the <code>genesis-structural-wraps</code> theme support data. If so, then the * <code>$output</code> may be echoed or returned. * * @since 1.6.0 * * @param string $context The location ID. * @param string $output Optional. The markup to include. Can also be 'open' * (default) or 'closed' to use pre-determined markup for consistency. * @param boolean $echo Optional. Whether to echo or return. Default is true (echo). * * @return string Wrap HTML. */ function genesis_structural_wrap( $context = '', $output = 'open', $echo = true ) { $wraps = get_theme_support( 'genesis-structural-wraps' ); //* If theme doesn't support structural wraps, bail. if ( ! $wraps ) return; //* Map of old $contexts to new $contexts $map = array( 'nav' => 'menu-primary', 'subnav' => 'menu-secondary', 'inner' => 'site-inner', ); //* Make the swap, if necessary if ( $swap = array_search( $context, $map ) ) { if ( in_array( $swap, $wraps[0] ) ) $wraps[0] = str_replace( $swap, $map[ $swap ], $wraps[0] ); } if ( ! in_array( $context, (array) $wraps[0] ) ) return ''; //* Save original output param $original_output = $output; switch ( $output ) { case 'open': $output = sprintf( '<div %s>', genesis_attr( 'structural-wrap' ) ); break; case 'close': $output = '</div>'; break; } apply_filters( 'genesis_structural_wrap-' . $context, $output, $original_output ); if ( $echo ) echo $output; else return $output; }
July 22, 2014 at 3:47 pm #115450saxismeMemberHi @aaronc,
did you managed to solve it?
I am in the same situation.I've found this piece of code
add_action( 'genesis_setup', 'srf_add_cust_classes', 15 ); // Priority 15 ensures it runs after Genesis itself has setup. function srf_add_cust_classes() { add_filter( 'genesis_attr_site-inner', 'srf_attr_site_inner' ); } function srf_add_class( $attr, $class ) { $attr['class'] .= ' ' . sanitize_html_class( $class ); return $attr; } function srf_attr_site_inner( $attr ) { return srf_add_class( $attr, 'example-class-1' ); }
here but can't make it work.
Thanks.
July 22, 2014 at 3:53 pm #115452saxismeMemberHi @aaronc,
I've found the solution thanks to Sridhar Katakam:
add_filter( 'genesis_attr_site-inner', 'custom_attributes_content' ); function custom_attributes_content( $attributes ) { if ( is_page() || is_front_page() ) { //I need it only for this type of content $attributes['id'] = 'site-inner'; } return $attributes; }
Cheers!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.