[Resolved] featured-image-active class still included in body when it shouldn’t

Home Forums Support [Resolved] featured-image-active class still included in body when it shouldn’t

Home Forums Support featured-image-active class still included in body when it shouldn’t

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #1522775
    George

    When disabling the featured image from the page or post through the Disable Elements section, the featured-image-active class is still being added to the body. As a result, it creates confusion in cases when I want to style the page when the featured image is not present. Is that a bug?

    #1522859
    Leo
    Staff
    Customer Support

    Hi George,

    Looks like it.

    I’ll confirm with Tom and report back ๐Ÿ™‚

    #1522995
    George

    Ok, thanks Leo. If it’s a bug, I would appreciate it if Tom provided the code that he’s going to use for the update as I need to finish a project and I need the functionality. Unless there is another way.

    #1524248
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_filter( 'body_class', function( $classes ) {
        if ( is_singular() ) {
            $disable_featured_image = get_post_meta( get_the_ID(), '_generate-disable-post-image', true );
    
            if ( $disable_featured_image ) {
                $classes = array_diff( $classes, array( 'featured-image-active' ) );
            }
        }
    
        return $classes;
    } );
    #1524453
    George

    Hi Tom, doesn’t seem to be working, still outputting the class when the featured image / Page Header is disabled from the page.

    #1524454
    George

    Ok, Tom, it’s working, had to increase the priority to 20.

    Is that a temporary solution, are you planning on fixing that in an upcoming update?

    #1524486
    Tom
    Lead Developer
    Lead Developer

    We’ll fix this in GPP 1.13.0 ๐Ÿ™‚

    #1524488
    George

    Perfect, thanks, Tom!

    #1718970
    George

    Hey, Tom. I noticed that the issue hasn’t been fixed in GPP 2.0 beta.

    #1719354
    Tom
    Lead Developer
    Lead Developer

    Thanks for the heads up – looks like this one slipped through!

    #1736492
    George

    Hi Tom. I still don’t see that fixed in the RC for GPP 2.0 unless it’s a GP free issue. I currently have this code that works only for posts:

    add_filter( 'body_class', function( $classes ) {
        if ( is_singular() ) {
            $disable_featured_image = get_post_meta( get_the_ID(), '_generate-disable-post-image', true );
    
            if ( $disable_featured_image ) {
                $classes = array_diff( $classes, array( 'featured-image-active' ) );
            }
        }   
    
        return $classes;
    }, 20);

    How do I asjust it to affect pages as well?

    #1737335
    Tom
    Lead Developer
    Lead Developer

    Yea sorry about that, it didn’t make it through on this one. There are a couple of things to take into consideration that I want to think about/get right.

    That code should work the same for posts and pages (is_singular() applies to both).

    Is the page using the Disable Elements metabox, or a Layout Element?

    #1737383
    George

    Disable Elements metabox.

    #1738182
    Tom
    Lead Developer
    Lead Developer

    Strange, that should work fine then.

    What if you add var_dump('hi'); above the array_diff line? Does it output anything on the site?

    #1738337
    George

    Ah, no! It’s working fine for pages. There is an issue where the featured image is disabled from the Customizer. What would be the condition to remove the class for them?

Viewing 15 posts - 1 through 15 (of 23 total)
  • The topic ‘featured-image-active class still included in body when it shouldn’t’ is closed to new replies.