WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] trying to remove the search form in 2011 header section (14 posts)

  1. 5high
    Member
    Posted 2 years ago #

    Hi, I'd be grateful of any help with eliminating the search box that appears in the header section of 2011 theme (in a page so it's in //html/body/div/header/form)
    I want to make some other changes, so have already made a child template with a style.css & functions.php as per w/p tutorials. I can find the code that I want to omit using firebug, which is:-

    <form id="searchform" action="http://localhost/" method="get">
    <label class="assistive-text" for="s">Search</label>
    <input id="s" class="field" type="text" placeholder="Search" name="s">
    <input id="searchsubmit" class="submit" type="submit" value="Search" name="submit">
    </form>

    and I've tried adding in a remove_action to the child functions.php like this:-

    remove_action('wp_blog_header', '<form method="get" id="searchform" action="http://localhost/">' );

    but it has no effect... I've obviously not referenced the action properly (NB: using localhost as designing it on my testing server) so would really appreciate any help with this! Thanks.

  2. egado
    Member
    Posted 2 years ago #

  3. 5high
    Member
    Posted 2 years ago #

    Thanks for getting back to me - I never thought of looking on u-tube - have spent DAYs looking through the codex etc though. I can see how that works, but I though it wasn't good practice to copy files to the child theme (to then edit) as it means twice the # of files to load + it wouldn't allow for full updates?? I've read it's better to just add in the required changes to a style/functions file in the child theme??
    However i was getting desperate this am and have just tried this...

    /* to stop Search Form in header area*/
    #branding #searchform {
    		display: none;
    }

    by adding it to my child style.css file which seems to have worked... Is this OK too???

  4. egado
    Member
    Posted 2 years ago #

    ChildThemes
    Theme updates are no problem. Only the functions.php and the style.css in your childtheme will be load additional. So wordpress use the parent theme functions.php and style.css and then add yours. All other files will be loaded instead of the parent theme files.

    But your right, if there is a possibility to remove or add things/functions through the functions.php or style.css – it might be better.

    So your solution might be "ok" - the search field won't be shown. But it is still there in your code, so screenreaders or google (eg.) will still "see/read" it.

  5. 5high
    Member
    Posted 2 years ago #

    Hi - thanks so much for your help. Whilst trying to find a solution to getting rid of the code completely (for the search form in the header.php) as well as the site title and tag line area (ie leaving only the header image + main horizontal menu/nav) I copied the 2011 header.php to my child theme, then deleted the code that I didn't want - which worked v well but still leaves me with the problem of having to check for changes with each update...
    Since then I've run the most recent updates for 2011 & wp and low and behold 2011 offers just the sort of edits I was trying to do with my child theme (for the title) - Hurray! - so I've made the changes via the wp-admin and deleted the header.php in my Child theme - BUT I'm back to where I started with the search box: so it's still not showing because of the code below, in my child style.css

    /* to stop Search Form in header area*/
    #branding #searchform {
    		display: none;

    but it's container remains an issue for the available space for the main horizontal menu - so I need to get rid of it all!
    I've scoured the wp forums and utube tutorials and ALL of them basically say to copy the header.php then delete/comment out the code - so NOT good for future updates to the 2011 header.php file.
    Please, I'd really appreciate any help with this - I guess what I'm after is the correct way to 'cancel' the search form via my Child theme functions.php file, so that it remains bullet-proof for further updates.... Thanks.

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    You cannot do it with functions.php, only by editing header.php or using the style.css file.

    For other readers of this topic:
    If you are using a child theme it is easy, just do the following, copy header.php from the parent theme, paste this to the child themes directory.

    Open the new header.php file in the child theme, lines 115 to 126 deal with the search box, remove or edit the layout code in this new file to suit your changes.

    If the template file exists in the child theme then this will be loaded and not the parents.

    As already said when the next update comes out you should check to see if there are any changes you need to add to your child theme.

    style.css : stylesheet
    Another option use the style.css for the search setting the height to zero, hide it, or send it off screen with right: 99999px; that should free up the space!

    .only-search,
    #branding #searchform {
       display: none;
       right: 99999px;
    }

    HTH

    David

  7. 5high
    Member
    Posted 2 years ago #

    Hi David,
    Thanks for your help - I've changed my child style.css to include the 'right: 99999px', and tried both with & without the '.only-search,' at the beginning and although it still eliminates the search form, it doesn't free-up the right-hand space on the main horizontal nav bar; so when the screen is narrowed the nav bar becomes 2 lines rather than spreading to the right-hand end - though I haven't yet re-done the child header a/a. I've also tried changing the right-hand margin on the '#access' via my child style.css but it doesn't fix it!
    But I'd be really interested to know why you can't use the child functions.php to stop the search box from loading?? Is it that you can only 'modify' functions this way, but have to comment them out/delete them in copied files to your child theme to actually STOP unwanted functions?? Or is there some php code that could do this?? - and yes I'm still on the Holy Grail of totally upgradeable Child Themes, as I intend to use mine across several sites, so it's quite important to me for it to be quick and accurate. It does seem to be an issue for lots of people besides myself, and would be great to find a 'perfect fix' for it particularly as child themes are becoming more popular...Fingers crossed! Thanks.

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    Try this, copy searchform.php to the child theme and empty it, if the child themes searchform.php over-rides the parents as it should, then that should deal with the search form.

    it doesn't free-up the right-hand space on the main horizontal nav bar

    The default Twenty Eleven does not have the search in the navigation, it has it top right in the header, in the #branding, if you have added the search in the navigation from another tutorial, just reverse the changes?

    Regards

    David

  9. 5high
    Member
    Posted 2 years ago #

    Brilliant! Very nice 'clean' idea that works well - except it doesn't solve the problem of the right-hand space being limited by something in the horizontal nav menu. So perhaps it was due to another factor all along??
    I've searched it via firebug and dreamweaver and the only thing I can think of is a styling issue of the primary menu in the nav id # access (I titled mine 'menu-main_site_menu-container'). So here's the code for the area...

    <nav id="access" role="navigation">
    <h3 class="assistive-text">Main menu</h3>
    <div class="skip-link">
    <div class="skip-link">
    <div class="menu-main_site_menu-container">
    <ul id="menu-main_site_menu" class="menu">

    but I can't find anything that affects the right-hand margin - in fact I can't find a style.css item that styles the menu-container at all!! only php files which don't seem to relate to the width either.
    Any ideas??? Thanks.

  10. 5high
    Member
    Posted 2 years ago #

    Well, by chance while I was looking for the heirarchy of the page title styling in the 2011 style.css I spotted this code under branding:

    #branding .only-search + #access div {
    	padding-right: 205px;
    }

    which seemed to have a HUGE amount of right-hand padding & in the #access div... so I've added this into my child theme style.css:

    /*
    to eliminate blocked space in main menu nav bar from searchform in header
    */
    #branding .only-search + #access div {
    	padding-right: 0px;
    }

    which has solved the problem!!!

    BUT I'm not certain whether it will ONLY effect the right padding in the main nav area, rather than anything to do with a search page?? Can anyone help with this??
    Thanks.

  11. 5high
    Member
    Posted 2 years ago #

    As no ideas here, I'll post this query in the coding forum as it's probably more appropriate.
    But thanks for all help with this :)

  12. 5high
    Member
    Posted 2 years ago #

    Have got a reply from the Hacks sub-forum, that my above code is fine and won't have any other effects in my site!

    So if anyone else wants to clear out that pesky right-hand block in the access div, this is it!

    Thanks to all who helped.

  13. AndyLaws
    Member
    Posted 2 years ago #

    I had the same problem, tried to fix it, the last one move - copying searchform.php to the child theme and emptying it, and it also didnt work..

  14. 5high
    Member
    Posted 2 years ago #

    Hi Andy,
    if you add the extra bit about the #branding .only-search + #access div into your child syle.css it totally removes the blocked right-hand part of the menu/nav area. See my post 1 wk ago with the new code needed.
    Good luck!

Topic Closed

This topic has been closed to new replies.

About this Topic