WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Eleven Theme exclude Search on specific page (7 posts)

  1. Malae
    Member
    Posted 1 year ago #

    Is there a way to exclude Search from the header of a specific page?
    I am building a site and have long Glossary page with the alphabet A to Z accross the top with links to allow user to go directly to a specific letter. This worked fine, except that if S is selected the page goes to the top of the page with all browswers except IE. After I worked out that it was caused by the link going to Search in the header, I commented out the relevant part from the header.php file and Search disappeared along with the problem.
    My site has no blogging, but I would like to keep the Search for other pages. Any ideas if this can be done, by excluding from the page with the problem?

  2. paulwpxp
    Font hero
    Posted 1 year ago #

    Add in the || (or) to the if conditional check in this block of code.

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( $header_image ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>

    So just this line

    if ( 'blank' == get_header_textcolor() ) :

    Replaced with this

    if ( 'blank' == get_header_textcolor() || is_page('99') ) :

    Where 99 is the page id of that page.

  3. Malae
    Member
    Posted 1 year ago #

    Thank you paulwpxp for your fast reply. I made the change with great expectations of solving my problem, but alas it didn't work. This may be due to my ignorance of some finer point or other lack of understanding. I took the page id from the Permalink: .... page_id=2340 after opening the Edit Page in question. I then substituted the 2340 for 99 so the line became:

    if ( 'blank' == get_header_textcolor() || is_page('2340') ) :

    When I opened the page I found the Search on every page. Being a newcomer to this coding, I tried many changes of spacing, taking out the commas, brackets, adding id= etc., but could not make any work. I would really like to know how to make this work. For the time being, I have now returned to my Search-free pages. :)

  4. paulwpxp
    Font hero
    Posted 1 year ago #

    @Malae I'm sorry, the code above is wrong.

    Use this instead

    Find this block of code

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( $header_image ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>
    <?php
    	else :
    ?>
    	<?php get_search_form(); ?>
    <?php endif; ?>

    Replace with this

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() || !is_page(2340) ) :
    ?>
    	<div class="only-search<?php if ( $header_image ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>
    <?php
    	elseif ( !is_page(2340) ) :
    ?>
    	<?php get_search_form(); ?>
    <?php endif; ?>
  5. Malae
    Member
    Posted 1 year ago #

    Hi paulwpxp,
    Thanks for giving it another shot, but still no luck. It does not remove Search from that page. Getting late here, so will wait until tomorrow and try it again.

  6. LittleBigThing
    Member
    Posted 1 year ago #

    Could a more simple, CSS-only solution not work?

    Use this piece of code below in your (child theme's) style.css:

    body.page-id-2340 searchform#idclass {
    display: none;
    }

    The first selector body.page-id-2340 should be used as is. This selects the right page (Glossary).

    For the second selector, you should look for the id or class of your search form and replace searchform#id by that. You can do this using Firefox' Web developer extension.

    You might like to add a specific selector for the header in-between the two selectors if you have another search form somewhere else on the same page.

  7. Malae
    Member
    Posted 1 year ago #

    Thanks for suggesting the CSS approach. I have temporarily solved the problem on the Glossary page by using a search widget, which I can put at the bottom of one page. I chose the Home page, which gives users access to Search at least on one page. I will certainly try your suggestion as soon as I have time.

Topic Closed

This topic has been closed to new replies.

About this Topic