• I’ve added the below code to my functions file and it’s working fine.

    add_action( 'genesis_before_content_sidebar_wrap', 'bw_category_header' );
    function bw_category_header() {
      if( is_category() )
        echo '<h1 class="archive-title">';
        echo single_cat_title();
        echo '</h1>';
    }

    A few lines down, I added the following and it’s showing on every page. It’s not respecting the if ( is_page( 21 ) ) part.

    add_action( 'genesis_before_content_sidebar_wrap', 'bw_blog_header' );
    function bw_blog_header() {
      if ( is_page( 21 ) )
        echo '<h1 class="archive-title">';
        echo wp_title();
        echo '</h1>';
    }

    If I add curly brackets inside the if statement of the second function, it doesn’t show on the pages where it shouldn’t, but it also doesn’t show on page 21.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You’re missing a set of braces around what the if is executing. They are required if you are executing more than one command in the if statement.

    add_action( 'genesis_before_content_sidebar_wrap', 'bw_blog_header' );
    function bw_blog_header() {
      if ( is_page( 21 ) ) {
        echo '<h1 class="archive-title">';
        echo wp_title();
        echo '</h1>';
        }
    }
    Thread Starter Brad West

    (@bradawest)

    The second function ignores the if statement and adds the code to all pages without the curly braces. If I add the curly braces, it doesn’t show on any page; not even page 21.

    And to make matters more fuzzy, the first function doesn’t need the curly braces to operate.

    In PHP, if an IF statement is executing one line it will work without the curly braces. If it is executing more than one line it requires the curly braces, otherwise it will just execute the first line.

    Try adding the curly braces in both functions and see how that works.

    Thread Starter Brad West

    (@bradawest)

    I added the curly braces around the if statements in both functions and the same thing occurs. The first function executes as you’d expect and the second one does nothing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘if ( is_page() ) Showing on Every Page or Not Showing at All’ is closed to new replies.