generate_do_element_classes
-
hiya nice GP peeps π
i’m trying to implement the
generate_do_element_classesfunctionality in a theme i’m creating from scratch (as a self-taught tutorial), but i’m gettingUndefined variable: classes errorand a warning thatjoin() has too few args (1).the code does output part of the attribute in the target element but the string is empty, like this
class=""i really enjoy learning how GP code works and would greatly appreciate any guidance if you have a moment… no worries if not.
thank you <3!
my theme-functions.php:
function mysite_do_element_classes( $context, $class = '' ) { $after = apply_filters( 'mysite_after_element_class_attribute', '', $context ); if ( $after ) { $after = ' ' . $after; } echo 'class="' . join( ' ', mysite_get_element_classes( $context, $class ) ) . '"' . $after; } function mysite_get_element_classes( $context, $class = '' ) { $classes = array(); if ( ! empty( $class ) ) { if ( ! is_array( $class ) ) { $class = preg_split( '#\s+#', $class ); } $classes = array_merge( $classes, $class ); } $classes = array_map( 'esc_attr', $classes ); return apply_filters( "mysite_create_{$context}_class", $classes, $class ); }my markup.php:
if ( ! function_exists( 'mysite_create_header_classes' ) ) { add_filter( 'mysite_create_header_class', 'mysite_create_header_classes' ); function mysite_create_header_classes( $classes ) { $classes[] = 'site-header'; } return $classes; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘generate_do_element_classes’ is closed to new replies.
