Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Disable “Content Title” on a post not working with my Block Element

  • Hi there!

    I’m having trouble disabling the title of a specific page using the Disable Elements feature in GeneratePress. Unfortunately, it seems like the title is part of a Block Element, and disabling it isn’t working.

    Do you know of a CSS class that I can add to my Block Element so that it will be disabled when I check the “Content Title” in the Disable Elements metabox of a specific post?

    Thanks for your help!

  • Hi there,

    The Disable elements can only control the default elements, the elements added by a block element are excluded.

    However, you can create another block element without the title and assign it to where you don’t want the title to appear.

    Then go back to the original block element, exclude the pages from the location list.

    Let me know if this helps!

  • Thank you Ying. I know I can do that but I was hoping for a more “dynamic” solution where my users can simply check the Disable Elements bock to change the display.

    I know the equivalent can be done for a Featured Image by adding the “page-header-image” css class to the image in my Content Template element.

  • Unforutnlay, there’s no such way.

    I know the equivalent can be done for a Featured Image by adding the “page-header-image” css

    That’s actually a bug as all the disable elements are supposed to be controlled by PHP not CSS, this is a bug we need to fix, and once the bug is fixed, the CSS class would not work anymore.

    All the other disable elements are controlled by PHP, except the featured image option in the page editor. The featured image option in the layout element is already controlled by PHP so it will remove all the related HTML as well, not just using CSS to hide it. Hope that makes sense.

  • Ying, ok that makes sense. But why remove this option? It would easily be made flexible by adding a css class to the body element, and let users use it to customize their layout via css

  • Hi there,

    to your original question:

    GP has the generate_show_title() that can be used to determine of the title is enabled or disabled.

    Theres lots of ways to use it for exmaple this snippet:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 123 === $element_id && ! generate_show_title() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Will disable a GP Element with the ID of 123 if the post has the title disabled.

    Or this:

    add_filter( 'render_block', function( $block_content, $block ) {
    
        if ( 
            !is_admin() && 
            ! generate_show_title() &&
            ! empty( $block['attrs']['className'] ) && 
            'your-custom-class' === $block['attrs']['className'] 
        ) {
    		
            $block_content = '';
    
        }
    
        return $block_content;
    
    }, 10, 2 );

    Which will remove a Block with a class of your-class-name if the the title is disabled.

    These methods are better then CSS as they actually remove the HTML

    Let me know if that helps

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.