• Resolved Pat K

    (@blackcapdesign)


    This is not a support request. I found a glitch and I’m sharing a workaround:

    After running the WP 5.2 update on a few sites using LGC with a search shortcode, I noticed the search form was no longer being output inside LGC. It was being output ABOVE both columns. In other words, the form HTML had been structurally moved ABOVE both of the LGC columns. The column that should contain the form was now empty.

    I was using the following code via the child theme functions.php file to create the search shortcode:
    add_shortcode('customsearch', 'get_search_form');

    I replaced it with a custom search form …like this:

    function customsearchform( $form ) {
     
        $form = '<form role="search" method="get" id="customsearchform" action="' . home_url( '/' ) . '" >
        <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
        <input type="text" value="' . get_search_query() . '" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
        </div>
        </form>';
     
        return $form;
    }
    add_shortcode('customsearch', 'customsearchform');

    And the form is now being output inside the column again.

    I’m still not sure why this is happening; whether it’s specific to LGC or if it’s a WP 5.2 bug. Maybe Tom can shed some light on this.

Viewing 1 replies (of 1 total)
  • Thread Starter Pat K

    (@blackcapdesign)

    This is a better replacement custom search form example; contains a placeholder, and IDs are swapped out for CLASSES (so the form won’t generate validation errors if loaded more than once once per page):

    function customsearchform( $form ) {
     
        $form = '<form role="search" method="get" class="search-form" action="' . home_url( '/' ) . '" >
        <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
        <input type="search" value="' . get_search_query() . '" placeholder="Search ..." name="s" id="s" />
        <input type="submit" class="search-submit" value="'. esc_attr__('Search') .'" />
        </div>
        </form>';
     
        return $form;
    }
    add_shortcode('customsearch', 'customsearchform');
Viewing 1 replies (of 1 total)
  • The topic ‘Layout problem after WP 5.2 update using LGC and search shortcode’ is closed to new replies.