• Resolved chrisTb

    (@christb)


    Trying to add a search form to my primary nav on wordpress site: christinatbhotz.com. It works beautifully on MAMP but nothing shows up when live.

    This is what it looks like locally.

    This is what it looks like when I take out the primary menu logic when it’s live.

    No search boxes show up at all when the primary logic is still in place.

    Functions code is below.

    // Search in Nav
    
    add_filter('wp_nav_menu_items', 'add_search_menu', 10, 2);
    function add_search_menu($items, $args) {
    if ( 'primary' != $args->theme_location )
    return $items;
    
    ob_start();
    get_search_form();
    $searchform = ob_get_contents();
    ob_end_clean();
    $items .= '<class="site-nav">' . $searchform . '';
    return $items;
    }
    
    // Add to your init function
    add_filter('get_search_form', 'my_search_form');
    
    function my_search_form($text) {
         $text = str_replace('value="Search"', 'value=""', $text);
         return $text;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Did you dump the variables at each line to make sure they are what you think they are.

    function add_search_menu($items, $args) {
      var_dump($args);

    Thread Starter chrisTb

    (@christb)

    I didn’t. I’m not sure what that means. I’m new to wordpress, so could you either explain what that does and where it should go, or provide me with a link that will help me sort it out?

    Its not a WordPress thing, its a php debugging statement that will output the value of a variable. It helps you check that a variable contains the value(s) that you think it should do. Temporarily add it in one line at a time until you find the problem. The screen output will be messed up a bit but the variable’s value should be shown for you to inspect. var_dump works on any type of varaiable, whereas an echo doesn’t work on arrays or objects.

    https://php.net/manual/en/function.var-dump.php

    Thread Starter chrisTb

    (@christb)

    I accidentally discovered that the error has something to do with the WP Conditional Logic plugin I had installed. I wasn’t actually using it, but it was still active and somehow that interferes. I’ll be testing further on MAMP and will be in contact with the Plugin’s developers regarding how it interacts with the added search function.

    Thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Function not working when Live’ is closed to new replies.