'; } } add_action( 'wp_head', 'arrival_pingback_header' ); /** * Adds async/defer attributes to enqueued / registered scripts. * * If #12009 lands in WordPress, this function can no-op since it would be handled in core. * * @link https://core.trac.wordpress.org/ticket/12009 * @param string $tag The script tag. * @param string $handle The script handle. * @return array */ function arrival_filter_script_loader_tag( $tag, $handle ) { foreach ( array( 'async', 'defer' ) as $attr ) { if ( ! wp_scripts()->get_data( $handle, $attr ) ) { continue; } // Prevent adding attribute when already added in #12009. if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) { $tag = preg_replace( ':(?=>):', " $attr", $tag, 1 ); } // Only allow async or defer, not both. break; } return $tag; } add_filter( 'script_loader_tag', 'arrival_filter_script_loader_tag', 10, 2 ); /** * Generate preload markup for stylesheets. * * @param object $wp_styles Registered styles. * @param string $handle The style handle. */ function arrival_get_preload_stylesheet_uri( $wp_styles, $handle ) { $preload_uri = $wp_styles->registered[ $handle ]->src . '?ver=' . $wp_styles->registered[ $handle ]->ver; return $preload_uri; } /** * Adds preload for in-body stylesheets depending on what templates are being used. * Disabled when AMP is active as AMP injects the stylesheets inline. * * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content */ function arrival_add_body_style() { // If AMP is active, do nothing. if ( arrival_is_amp() ) { return; } // Get registered styles. $wp_styles = wp_styles(); $preloads = array(); // Preload content.css. $preloads['arrival-content'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-content' ); // Preload sidebar.css. if ( is_active_sidebar( 'sidebar-1' ) ) { $preloads['arrival-sidebar'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-sidebar' ); } // Preload comments.css. if ( ! post_password_required() && is_singular() && ( comments_open() || get_comments_number() ) ) { $preloads['arrival-comments'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-comments' ); } // Preload front-page.css. global $template; if ( 'front-page.php' === basename( $template ) ) { $preloads['arrival-front-page'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-front-page' ); } // Output the preload markup in
. foreach ( $preloads as $handle => $src ) { echo ''; echo "\n"; } } add_action( 'wp_head', 'arrival_add_body_style' ); /** * Add dropdown symbol to nav menu items with children. * * Adds the dropdown markup after the menu link element, * before the submenu. * * Javascript converts the symbol to a toggle button. * * @TODO: * - This doesn't work for the page menu because it * doesn't have a similar filter. So the dropdown symbol * is only being added for page menus if JS is enabled. * Create a ticket to add to core? * * @param string $item_output The menu item's starting HTML output. * @param WP_Post $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. * @return string Modified nav menu HTML. */ function arrival_add_primary_menu_dropdown_symbol( $item_output, $item, $depth, $args ) { // Only for our primary menu location. /*if ( empty( $args->theme_location ) || 'primary' != $args->theme_location || 'top' != $args->theme_location ) { return $item_output; }*/ // Add the dropdown for items that have children. if ( ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) { return $item_output . ''; } return $item_output; } add_filter( 'walker_nav_menu_start_el', 'arrival_add_primary_menu_dropdown_symbol', 10, 4 ); /** * Filters the HTML attributes applied to a menu item's anchor element. * * Checks if the menu item is the current menu * item and adds the aria "current" attribute. * * @param array $atts The HTML attributes applied to the menu item's `` element. * @param WP_Post $item The current menu item. * @return array Modified HTML attributes */ function arrival_add_nav_menu_aria_current( $atts, $item ) { /* * First, check if "current" is set, * which means the item is a nav menu item. * * Otherwise, it's a post item so check * if the item is the current post. */ if ( isset( $item->current ) ) { if ( $item->current ) { $atts['aria-current'] = 'page'; } } else if ( ! empty( $item->ID ) ) { global $post; if ( ! empty( $post->ID ) && $post->ID == $item->ID ) { $atts['aria-current'] = 'page'; } } return $atts; } add_filter( 'nav_menu_link_attributes', 'arrival_add_nav_menu_aria_current', 10, 2 ); add_filter( 'page_menu_link_attributes', 'arrival_add_nav_menu_aria_current', 10, 2 ); /** * Social icons for the theme * */ add_action('arrival_social_icons','arrival_social_icons'); if( ! function_exists('arrival_social_icons')){ function arrival_social_icons(){ $arrival_icons_value = get_theme_mod('arrival_social_icons'); $arrival_icons = json_decode($arrival_icons_value); ?>