Support » Themes and Templates » Hide Featured Image if is_page_template

  • Resolved Native Imaging

    (@native-imaging)


    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 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi

    (@esmi)

    Forum Moderator

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

    Native Imaging

    (@native-imaging)

    Here’s what I have so far…..

    http://pastebin.com/EZBWvZnm#

    esmi

    (@esmi)

    Forum Moderator

    What exactly is the problem?

    Native Imaging

    (@native-imaging)

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

    Posted the change with comment in pastebin

    Thank YOu!:)

    Native Imaging

    (@native-imaging)

    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…

    esmi

    (@esmi)

    Forum Moderator

    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 {
    Native Imaging

    (@native-imaging)

    I think that works!! Thank You for your help!!! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide Featured Image if is_page_template’ is closed to new replies.