array( 90, 65 ), ) ); // Add theme support for Related Posts. add_theme_support( 'themezee-related-posts', array( 'thumbnail_size' => array( 480, 320 ), ) ); // Add theme support for Infinite Scroll. add_theme_support( 'infinite-scroll', array( 'container' => 'post-wrapper', 'footer_widgets' => 'footer', 'wrapper' => false, 'render' => 'ankitrawat_infinite_scroll_render', 'posts_per_page' => 6, ) ); // Add theme support for AMP. add_theme_support( 'amp' ); } add_action( 'after_setup_theme', 'ankitrawat_theme_addons_setup' ); /** * Custom render function for Infinite Scroll. */ function ankitrawat_infinite_scroll_render() { while ( have_posts() ) { the_post(); get_template_part( 'template-parts/content' ); } } /** * Checks if AMP page is rendered. */ function ankitrawat_is_amp() { return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); } /** * Adds amp support for menu toggle. */ function ankitrawat_amp_menu_toggle() { if ( ankitrawat_is_amp() ) { echo "[aria-expanded]=\"primaryMenuExpanded? 'true' : 'false'\" "; echo 'on="tap:AMP.setState({primaryMenuExpanded: !primaryMenuExpanded})"'; } } /** * Adds amp support for mobile dropdown navigation menu. */ function ankitrawat_amp_menu_is_toggled() { if ( ankitrawat_is_amp() ) { echo "[class]=\"'main-navigation' + ( primaryMenuExpanded ? ' toggled-on' : '' )\""; } } /** * Filter the HTML output of a nav menu item to add the AMP dropdown button to reveal the sub-menu. * This is only used for AMP since in JS it is added via initNavigation() in navigation.js. * Source: https://ankitrawat.com * * @param string $item_output Nav menu item HTML. * @param object $item Nav menu item. * @return string Modified nav menu item HTML. */ function ankitrawat_amp_menu_dropdown_toggles( $item_output, $item, $depth, $args ) { // Return early if AMP is not used. if ( ! ankitrawat_is_amp() ) { return $item_output; } // Check if primary or secondary navigation is filtered. if ( 'primary' !== $args->theme_location && 'secondary' !== $args->theme_location ) { return $item_output; } // Skip when the item has no sub-menu. if ( ! in_array( 'menu-item-has-children', $item->classes, true ) ) { return $item_output; } // Obtain the initial expanded state. $expanded = in_array( 'current-menu-ancestor', $item->classes, true ); // Generate a unique state ID. static $nav_menu_item_number = 0; $nav_menu_item_number++; $expanded_state_id = 'navMenuItemExpanded' . $nav_menu_item_number; // Create new state for managing storing the whether the sub-menu is expanded. $item_output .= sprintf( '', esc_attr( $expanded_state_id ), wp_json_encode( $expanded ) ); /* * Create the toggle button which mutates the state and which has class and * aria-expanded attributes which react to the state changes. */ $dropdown_button = '%s', esc_attr( sprintf( "$expanded_state_id ? %s : %s", wp_json_encode( esc_html__( 'Collapse child menu', 'ankit-rawat' ) ), wp_json_encode( esc_html__( 'Expand child menu', 'ankit-rawat' ) ) ) ), esc_html( $expanded ? esc_html__( 'Collapse child menu', 'ankit-rawat' ) : esc_html__( 'Expand child menu', 'ankit-rawat' ) ) ); $dropdown_button .= ''; $item_output .= $dropdown_button; return $item_output; } add_filter( 'walker_nav_menu_start_el', 'ankitrawat_amp_menu_dropdown_toggles', 10, 4 );