• I display sidebar with the command dynamic_sidebar(‘main_sidebar’) in single.php and define a new search form in searchform.php but the new search form does not display. What is the procedure to display the new search form in searchform.php?

    single.php:

    <aside id="sidebar">
    
    ? ? ? ? <?php dynamic_sidebar('main_sidebar'); ?>
    
    ? ? ? </aside>
    

    searchform.php:

    <form method="GET" action="<?php echo home_url(); ?>">
    
        <input type="search"  name="s" placeholder="Search Here..." value="<?php echo get_search_query(); ?>">
    
        <input type="submit" id="search-btn" value="">
    
    </form>

    functions.php

    function fcc_widgets(){
        register_sidebar([
            'name' => 'Main Sidebar',
            'id' => 'main_sidebar',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
             
        ]);
         
    }
    
    add_action('widgets_init', 'fcc_widgets');
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    You utilize searchform.php by calling get_search_form(); from a template file. This is unrelated to any widgets or blocks that are displayed with dynamic_sidebar(). If you want your custom search form HTML to appear in a dynamic widget area, you need to create a custom widget or block.

    Thread Starter wolfberryz

    (@wolfberryz)

    Thanx for reply!

    I’m following a tutorial where a custom widget called ‘Main Sidebar’ is created in the WordPress UI. The widget contains a search form, category list and post list. All objects inside the widget are displayed correctly, but in the tutorial the search form inside the widget gets customized just by creating the searchform.php file. When I do the same the searchform.php is just ignored. Seems odd I can not replicate what is done in the tutorial.

    Does you are answer imply that it is only possible to customize a search form inside a widget with CSS?

    • This reply was modified 1 year, 4 months ago by wolfberryz.
    Moderator bcworkz

    (@bcworkz)

    I’m not sure which tutorial you use, but I suspect “Main Sidebar” is the widget container and not the individual widget. An individual widget can include a theme’s searchform.php, but the default search widget doesn’t do that. You’d need a custom widget or one from a theme or plugin which uses the file.

    With CSS you can alter how existing widgets appear. You cannot change how they function with CSS. With your own custom widget, you can have it do anything you like and appear as you like.

    Thread Starter wolfberryz

    (@wolfberryz)

    I’ve defined an individual widget in functions.php with name ‘Main Sidebar’ and from appearance->widget in WordPress UI selected ‘Main Sidebar’ to include a search form:

    function fcc_widgets(){
        register_sidebar([
            'name' => 'Main Sidebar',
            'id' => 'main_sidebar',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
             
        ]);
         
    }

    The tutorial link where search field and searchform.php are defined:
    https://youtu.be/KibbYf9avko?t=14438

    • This reply was modified 1 year, 4 months ago by wolfberryz.
    • This reply was modified 1 year, 4 months ago by wolfberryz.
    • This reply was modified 1 year, 4 months ago by wolfberryz.
    • This reply was modified 1 year, 4 months ago by wolfberryz.
    Moderator bcworkz

    (@bcworkz)

    The code you show creates a sidebar or widget container, not the widget itself. It appears in the video they use the existing built-in search widget. That video is over 4 years old. The current default search widget does not use searchform.php. If you want a widget that uses searchform.php in recent WP versions I think you’d need to create your own.

    Thread Starter wolfberryz

    (@wolfberryz)

    Thanx bcworkz for clarifying

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Customizing search widget with searchform.php does not work’ is closed to new replies.