WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide Featured Image if is_page_template (8 posts)

  1. Native Imaging
    Member
    Posted 8 months ago #

    Hello.

    Im trying to write an if statement, basically hiding the featured image if a specific page template is chosen.

    Such as: page-no-featured-image.php

    I found this in the wordpress API codex:

    if ( is_page_template('about.php') ) {
    	// Returns true when 'about.php' is being used.
    } else {
    	// Returns false when 'about.php' is not being used.
    }

    Just not sure how to wrap this around the 2011 child theme header.php (header image) hook...

    I assume I would place:

    if ( is_page_template('page-no-featured-image.php') ) {
    	// nothing here
    } else {
    
     //then the request for the featured image that the WP 2011 theme uses
    
    }

    If anyone could help.. I will Paste bin what I have so far...

    I'm still learning PHP & WP Codex... bare with me :)

  2. esmi
    Forum Moderator
    Posted 8 months ago #

    The 2nd code example you posted above looks fine to me.

  3. Native Imaging
    Member
    Posted 8 months ago #

    Here's what I have so far.....

    http://pastebin.com/EZBWvZnm#

  4. esmi
    Forum Moderator
    Posted 8 months ago #

    What exactly is the problem?

  5. Native Imaging
    Member
    Posted 8 months ago #

    Sorry, figured it out...
    had the bracket in the wrong close tag...

    Posted the change with comment in pastebin

    Thank YOu!:)

  6. Native Imaging
    Member
    Posted 7 months ago #

    Hey esmi, thank you for being so prompt with helping...

    i have one other small question about adding another page template for the if statement:

    if ( is_page_template('page-full-no-feature.php') ) {
            // Returns true when 'page-full-no-feature.php' is being used.
    } else {

    If I wanted to add another page template to the if statement, would it be correct to place it like this?

    if ( is_page_template('page-full-no-feature.php, page-sidebar-no-feature.php') ) {
            // Returns true when 'page-full-no-feature.php' is being used.
    } else {

    Or:

    if ( is_page_template('page-full-no-feature.php', 'page-sidebar-no-feature.php') ) {
            // Returns true when 'page-full-no-feature.php' is being used.
    } else {

    Either way, i'm still getting the featured image showing on the newer page template...
    I was however experimenting with moving the header/featured image into the page templates themselves, but figured the if statement should simplify things a bit....

    Not sure if i'm doing this incorrectly, but looks like i need to write a little more CSS as well for the proper widths of the elements in the page template with the sidebar...

  7. esmi
    Forum Moderator
    Posted 7 months ago #

    Try:

    if ( is_page_template('page-full-no-feature.php) ||  is_page_template(page-sidebar-no-feature.php') ) {
            // Returns true when either page is being used.
    } else {
  8. Native Imaging
    Member
    Posted 7 months ago #

    I think that works!! Thank You for your help!!! :)

Reply

You must log in to post.

About this Topic