• <?php include (‘https://domain.com/wp-content/themes/themename/searchform.php&#8217;); ?>
    <?php echo do_shortcode(‘[wp_google_searchbox]’); ?>

    Ive tried both these the top shows nothing the bottom prevents the page from even loading.

    The only thing in searchform.php is the copy+paste of the “get-code” from the custom search defined at the appropriate link.

    I’ve set the id in the settings page as well even though im not planning on using the widget, I placed the widget in the sidebar for giggles and it works fine there.

    Not too sure what the issue is here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have the same question and the same lack of success with the php code above… Trying to put the search form on my 404 page instead of the default search. Mine also works fine in the widget. Thank you!

    Thread Starter kevinknapp49

    (@kevinknapp49)

    I ended up having to create a widget area.
    This is in my Theme Functions.

    /**
     * Register Widget Area.
     *
     */
    function search_widget_init() {
    
    	register_sidebar( array(
    		'name' => 'Google Search',
    		'id' => 'google-search',
    	) );
    }
    add_action( 'widgets_init', 'search_widget_init' );

    And this is in my header.

    <div id="search" class="col-lg-2 col-md-2 column">
    	<?php if ( is_active_sidebar( 'google-search' ) ) : ?>
    		<?php dynamic_sidebar( 'google-search' ); ?>
    	<?php endif; ?>
    </div>

    Thank you!

    Plugin Author WebshopLogic

    (@webshoplogic)

    The second form of the first post have to be working if you insert it to a place where html body content can be displayed. This ‘place’ can be the post part or page header (but not the html head section, because it is outside of html body) or footer, or any sidebar or widget, …

    <?php echo do_shortcode('[wp_google_searchbox]'); ?>

    For example this code is display the search box at the beginning of every post, if you include this into your functions.php of your active theme:

    function the_content_wgs( $content ) {
    	$content = do_shortcode('[wp_google_searchbox]') . $content; 
    	return $content;
    }
    add_filter( 'the_content', 'the_content_wgs', 30, 1 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding Custom Google Search to header’ is closed to new replies.