Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Notice: Trying to get properties on a non-object" in php Wordpress Select NavMenu
    primarykey
    data
    text
    <p>I have a Wordpress theme, where I would like to add a dropdown (select) menu in mobile view. I add the code in the header.php, the function.php and the jQuery in my custom.js file.</p> <p>It works very well (it's linking the url, it's clickable) if a menu exist on my "mainNav" menu section in WordPress.</p> <p>But if I turned off the menu, I get 2 notifications to the Developer Debug Bar plugin. "Notice: Trying to get properties on a non object" in line 45 and 50.</p> <p>Here's my code: <a href="http://i.stack.imgur.com/uNqru.png" rel="nofollow">http://i.stack.imgur.com/uNqru.png</a></p> <p>I think maybe if the navigation menu was empty, the values was empty, or nulled, but i don't know how the hack I correct it. Can anybody help me please? Thank you!</p> <pre><code>//DropDown Select Navigation for the Main Menu function wp_nav_menu_dropdown( $args = array() ) { $defaults = array( 'theme_location' =&gt; '', 'menu_class' =&gt; 'mainNav', ); $args = wp_parse_args( $args, $defaults ); if ( ( $menu_locations = get_nav_menu_locations() ) &amp;&amp; isset( $menu_locations[ $args['theme_location'] ] ) ) { $menu = wp_get_nav_menu_object( $menu_locations[ $args['theme_location'] ] ); $menu_items = wp_get_nav_menu_items( $menu-&gt;term_id ); ?&gt; &lt;select id="menu-&lt;?php echo $args['theme_location'] ?&gt;" class="&lt;?php echo $args['menu_class'] ?&gt;"&gt; &lt;option value=""&gt;&lt;?php _e( 'Navigation Menu' ); ?&gt;&lt;/option&gt; &lt;?php foreach( (array) $menu_items as $key =&gt; $menu_item ) : ?&gt; &lt;option value="&lt;?php echo $menu_item-&gt;url ?&gt;"&gt;&lt;?php echo $menu_item-&gt;title ?&gt;&lt;/option&gt; &lt;?php endforeach; ?&gt; &lt;/select&gt; &lt;?php } else { ?&gt; &lt;select class="menu-not-found"&gt; &lt;option value=""&gt;&lt;?php _e( 'Menu Not Found' ); ?&gt;&lt;/option&gt; &lt;/select&gt; &lt;?php } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload