Need help with adding custom menu content

For inject <span> into menu, you do it using below code: //Setup this code into your current function.php file add_filter(‘wp_nav_menu_items’,’add_span_in_menu’, 10, 2); function add_span_in_menu( $items, $args ) { if( $args->theme_location == ‘primary’) { $myContent=”YOURCONTENT” $items .= ‘<li><span class=”number”>’ . $myContent . ‘</span></li>’; } return $items; } Above snippet will add <span> with content to your … Read more

get_posts is duplicating

First you need to save the IDs of the posts from first loop you want to exclude in second loop into an array, and the use that array to exclude the posts. Also, always reset post data after query. Here’s your code with the modification. <div class=”row”> <?php $args = array( ‘posts_per_page’ => 1, ‘offset’ … Read more

Create a variable with string, array or multiple values

the last $file takes priority over the previous That’s because you assign the new value to the $file variable at every line. The only way I see you can do it by using the array: <?php // define directory list $directories = array( ‘home’, ‘pages’, ‘blog’, ‘single-posts’, ‘products’, ‘templates’, ‘products’ ); // run through directories … Read more

How to add custom nav_menu_css_class to certain menu only?

You just need the third argument $args, of which one of it’s properties is theme_location: function wpse_218377_nav_menu_css_class( $classes, $item, $args ) { if ( ! empty( $args->theme_location ) && $args->theme_location === ‘custom-menu’ ) { $classes[] = ‘footer–menu-item’; } // ALWAYS return, not from inside the if return $classes; } add_filter( ‘nav_menu_css_class’ , ‘wpse_218377_nav_menu_css_class’ , 10, … Read more