$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Is_single not working properly in genesis|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Is_single not working properly in genesis

matteradmin11PV0评论

I am currently creating a child theme for my website which uses Genesis as a parent theme. Now I am making single pages as per my choosing. So, I am removing the entry header from within HTML main and posting it after entry-header. my code looks like this.

remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
add_action( 'genesis_after_header', 'gp_page_header');

function gp_page_header(){
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
    ?>
    <div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url('<?php echo $image[0]; ?>')">
        <div class="wrap">
        <?php
        the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); 
        genesis_post_info();
        ?>

        </div>
    </div>
    <?php
 }

If didn't want to create this style for homepage and should be only applied to single pages. Here is what i am doing now.

remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
if(is_single()) {
add_action( 'genesis_after_header', 'gp_page_header');

function gp_page_header(){
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
    ?>
    <div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url('<?php echo $image[0]; ?>')">
        <div class="wrap">
        <?php
        the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); 
        genesis_post_info();
        ?>

        </div>
    </div>
    <?php
 }
}

But this way it doesn't work. If I use a conditional tag, it isn't working. I am confused at the moment. Also, I am using front-page.php as the template for home. Any help will be appreciated.

I am currently creating a child theme for my website which uses Genesis as a parent theme. Now I am making single pages as per my choosing. So, I am removing the entry header from within HTML main and posting it after entry-header. my code looks like this.

remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
add_action( 'genesis_after_header', 'gp_page_header');

function gp_page_header(){
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
    ?>
    <div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url('<?php echo $image[0]; ?>')">
        <div class="wrap">
        <?php
        the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); 
        genesis_post_info();
        ?>

        </div>
    </div>
    <?php
 }

If didn't want to create this style for homepage and should be only applied to single pages. Here is what i am doing now.

remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
if(is_single()) {
add_action( 'genesis_after_header', 'gp_page_header');

function gp_page_header(){
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
    ?>
    <div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url('<?php echo $image[0]; ?>')">
        <div class="wrap">
        <?php
        the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); 
        genesis_post_info();
        ?>

        </div>
    </div>
    <?php
 }
}

But this way it doesn't work. If I use a conditional tag, it isn't working. I am confused at the moment. Also, I am using front-page.php as the template for home. Any help will be appreciated.

Share Improve this question edited Mar 8, 2019 at 11:26 Gufran Hasan 6918 silver badges20 bronze badges asked Mar 8, 2019 at 5:50 Raashid DinRaashid Din 2182 silver badges19 bronze badges 1
  • 1 Your is_single() should be in the function - function gp_page_header() { if ( ! is_single() ) { return; } ... } – Sally CJ Commented Mar 8, 2019 at 6:20
Add a comment  | 

1 Answer 1

Reset to default 0

Please put your action add_action( 'genesis_after_header', 'gp_page_header'); in if condition not whole code.

if(is_single()){
  add_action( 'genesis_after_header', 'gp_page_header');
}

Your updated code:

if(is_single()) {
  add_action( 'genesis_after_header', 'gp_page_header');
}

function gp_page_header(){
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
    ?>
    <div class="post-hero" style="background-repeat: no-repeat;background-size:cover;background-image: -webkit-radial-gradient(left top, circle cover, rgba(100, 66, 255, 0.9) 15%, rgba(0, 108, 255, 0.9) 50%, rgba(12, 180, 206, 0.9) 85%), url('<?php echo $image[0]; ?>')">
        <div class="wrap">
        <?php
        the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); 
        genesis_post_info();
        ?>

        </div>
    </div>
    <?php
 }
Post a comment

comment list (0)

  1. No comments so far