urlencode( implode( '|', aspace_get_config('google_fonts', array("Roboto:400,400i,700,700i", "Roboto Slab:400,700" )) ) ), 'subset' => urlencode( 'latin,latin-ext' ), ); $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); return esc_url_raw( $fonts_url ); } } /*-------------------------------------------------------------- # Menu Work --------------------------------------------------------------*/ /** * @param $classes * @param $item * @param $depth *https://developer.wordpress.org/reference/classes/walker_nav_menu/ * Add top-level-item to top level menu items for easier styling. * * @return array */ function ign_nav_menu_css_class( $classes, $item, $args, $depth ) { if ( $item->menu_item_parent == 0 ) { //Count top level menu items $classes[] = 'top-level-item'; } if ( $depth >= 2 ) { //Count top level menu items $classes[] = 'nested-menu-item'; } return $classes; } add_filter( 'nav_menu_css_class', 'ign_nav_menu_css_class', 10, 4 ); /** * @param $item * @param $args *add buttons for dropdowns when there is a sub-menu. * surround anchor ( and buttons if there is one) * * @return string */ function ign_menu( $item, $args ) { $classes = $args->classes; $arrow = '
' . aspace_get_config('submenu_arrow_icon', '') . '
'; if ( in_array( 'menu-item-has-children', (array) $classes ) ) { $item .= ''; } return ''; } add_filter( 'walker_nav_menu_start_el', 'ign_menu', 10, 99 ); //add search bar to a menu function add_search_form( $items, $args ) { if ( $args->theme_location == 'top-menu' ) { $items .= ''; } return $items; } if ( aspace_get_config('search_menu_item', false) ) { add_filter( 'wp_nav_menu_items', 'add_search_form', 10, 2 ); } /*------- Menu Fallback --------*/ /** * Menu fallback. Link to the menu editor if that is useful. * * @param array $args from wp_nav_menu * * @return string * */ function link_to_menu_editor( $args ) { if ( ! current_user_can( 'manage_options' ) ) { return ''; } // see wp-includes/nav-menu-template.php for available arguments $link = $args['link_before'] . '' . $args['before'] . 'Add a menu' . $args['after'] . '' . $args['link_after']; // We have a list, then output the link in an li if ( false !== stripos( $args['items_wrap'], ' '' $output = sprintf( $args['items_wrap'], $args['menu_id'], $args['menu_class'], $link ); //add container if ( ! empty ( $args['container'] ) ) { $output = "<" . $args['container'] . "class='" . $args['container_class'] . "' id='" . $args['container_id'] . "'>" . $output . ""; } if ( $args['echo'] ) { echo $output; } return $output; } /** * @param $data * @param $file * @param $filename * @param $mimes * * @return array */ function svgs_disable_real_mime_check( $data, $file, $filename, $mimes ) { $wp_filetype = wp_check_filetype( $filename, $mimes ); $ext = $wp_filetype['ext']; $type = $wp_filetype['type']; $proper_filename = $data['proper_filename']; return compact( 'ext', 'type', 'proper_filename' ); } add_filter( 'wp_check_filetype_and_ext', 'svgs_disable_real_mime_check', 10, 4 ); /** * output_inline_svg logo function by filtering the logo returned * Outputs inline svg logo when using customizer or outputting theme logo using get_custom_logo function * @access public * * @param mixed $html * * @return void */ function aspace_design_output_inline_svg( $html ) { $logo_id = get_theme_mod( 'custom_logo' ); //made by wp with add_theme_support if ( get_post_mime_type( $logo_id ) == 'image/svg+xml' ) { $image = get_attached_file( $logo_id ); $html = preg_replace( "/]+\>/i", file_get_contents( $image ), $html ); //add an aria-label if none found if( ! preg_match('/aria-label=\"([^"]*)\"/', $html)){ $html = str_replace('' . get_bloginfo( 'name' ) . ' '; }//theme mod //if we are in the customizer preview get both image and site title and hide/show based on js if ( is_customize_preview() ) { return ''; } if ( is_front_page() ) { //$logo is the custom logo wrapped in a link return ''; } else { return ''; } } /** * @param $message * * @return string * * Add logo to login page inline by using the message area Above. That way it is inline svg */ function the_login_logo( $message ) { if ( empty( $message ) ) { return ign_logo(); } else { return ign_logo() . $message; } } add_filter( 'login_message', 'the_login_logo' ); /** * Login page logo points to home page instead of WordPress */ function ign_login_url() { return esc_url( home_url() ); } add_filter( 'login_headerurl', 'ign_login_url' ); /*-------------------------------------------------------------- # Google Font Loading --------------------------------------------------------------*/ /** * Add pre-connect for Google Fonts. This makes them load faster * * @param array $urls URLs to print for resource hints. * @param string $relation_type The relation type the URLs are printed. * * @return array $urls URLs to print for resource hints. * @since Aspace 1.1.5.9.2 * */ function aspace_design_resource_hints( $urls, $relation_type ) { if ( wp_style_is( 'aspace-design-fonts', 'queue' ) && 'preconnect' === $relation_type ) { $urls[] = array( 'href' => 'https://fonts.gstatic.com', 'crossorigin', ); } return $urls; } add_filter( 'wp_resource_hints', 'aspace_design_resource_hints', 10, 2 ); /** * @param $block_content * @param $block * * @return string * Some blocks are too naked to work nicely like ul which needs its own margins and when inside container-content they dont play nice. */ function surround_block( $block_content, $block ) { if ( empty( trim( $block_content ) ) ) { return $block_content; } if ( $block['blockName'] == 'core/list' ) { return sprintf( '
%2$s
', sanitize_title( $block['blockName'] ), $block_content ); } return $block_content; } add_filter( 'render_block', 'surround_block', 10, 2 );