Show some menu sub items as dropdown under a menu item

Remove the first closing </li> and wrap the sub-items inside <ul></ul>, then close the parent <li>. For Example: function my_custom_menu_item($items, $args) { if(is_user_logged_in() && $args->theme_location == ‘primary’) { $user=wp_get_current_user(); $name=$user->display_name; $items .= ‘<li><a href=””>’.$name.'</a>’; $items .= ‘<ul>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-profile”>My Profile</a></li>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-posts”>My Posts</a></li>’; $items .= ‘<ul>’; $items .= ‘</li>’; } return … Read more

If Array Values Match Another Array’s Values, Then

Here’s one way to solve this: sort both arrays loop through them and compare them item by item (they should be equal, because arrays are sorted) . sort( $evaltypesReq ); sort( $evaltypesSch ); $containsAllValues = true; foreach ( $evaltypesReq as $k => $v ) { if ( $evaltypesSch[$k] !== $v ) $containsAllValues = false; }

Using Static HTML instead of the `home_url()` WP function

href=”https://wordpress.stackexchange.com/questions/350287/./contact-page” if you’re on the homepage (/) this will become: /contact-page if you’re on another page named foo (/foo/) this will become /foo/contact-page This is due to ./ being a relative path. To avoid struggles like this, the method via home_url() is preferred because it creates absolute links/paths that will work from anywhere you call … Read more

Undefined variable error in new function

I believe that’s telling you that $post (in $post->ID) is undefined. Try this instead: function sh_reading_time() { $content = get_post_field( ‘post_content’, get_the_ID() ); $word_count = str_word_count( strip_tags( $content ) ); $readingtime = ceil($word_count / 200); if ($readingtime == 1) { $timer = ” minute”; } else { $timer = ” minutes”; } $totalreadingtime = $readingtime … Read more

Can’t switch to a child theme using filters template, option_template and option_stylesheet

For a parent theme, template and stylesheet should be the same, which is the name of the parent theme directory. But for a child theme, template should be the parent theme’s directory name, whereas stylesheet is the child theme’s directory name. So if you’ve got the following: Parent theme: Twenty Nineteen (directory name: twentynineteen) Child … Read more

woocommerce specific quantities for product

Try this in your functions.php: add_filter( ‘woocommerce_quantity_input_args’, ‘control_product_qty_input’, 20, 2 ); function control_product_qty_input( $args, $product ) { $settings = array(’49’ => 3, ’48’ => 10); // for product id 49 3 products set foreach ($settings as $k => $v) { if($k === $product->get_id()){ $args[‘max_value’] = $v; $args[‘min_value’] = $v; } } return $args; } Note: … Read more

Why get_user_by() doesn’t work in my code?

I tweaked your code to make sure the $email was defined before attempting to process. I stop where the problem may be. If you follow all the if and else code, the “continue”resident when an email address is NOT a part of a particular group (subscriber, admin, customer etc) will skip the processing and move … Read more