Forums

I want search bar to only show on main page (4 posts)

  1. drew8818
    Member
    Posted 1 year ago #

    What code do you need to insert so that the search box only appears on the home page? Where exactly do you need to place it? Which .php file? Thanks

  2. renato_s
    Member
    Posted 1 year ago #

    It depends on where is your searchbox (header, sidebar, etc.) in your theme.

    Once you find the code, use conditional tags to show the search box only in the homepage:

    <?php if ( is_front_page() ) {
        // Search box code
    } ?>

    http://codex.wordpress.org/Conditional_Tags

  3. drew8818
    Member
    Posted 1 year ago #

    Thank you. Where is the widget search code usually found? I have a "middle" widget. Once I find the code, where do I locate it exactly?

  4. renato_s
    Member
    Posted 1 year ago #

    If the search box is a widget, you must use a plugin such as widget logic. In the search widget option put is_front_page(). Note that this only applies if you used a widget to insert the search box (Appearance > Widgets > drag the box to the sidebar).
    http://wordpress.org/extend/plugins/widget-logic/

    If the searchbox is hardcoded to your theme, you have to locate the code (most likely it's in sidebar.php, judging by what you said) and:

    Put
    <?php if ( is_front_page() ) { ?>
    before it starts...

    ...and
    <?php } ?>
    after it.

Topic Closed

This topic has been closed to new replies.

About this Topic