[Resolved] GP Layout based on post date

Home Forums Support [Resolved] GP Layout based on post date

Home Forums Support GP Layout based on post date

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1587872
    Richard

    Dear GP team,

    Is there a way to apply a GP Layout to all posts that have been created before a specific date?

    Background: As part of a themeswitch (genesis + WPBakery –> GP), I want to utilise the standard theme sidebar functionality. In the old theme the sidebar was part of the post (wpbakery template). So the plan is to have the default layout (with sidebar) for posts created from now on (with generatepress) while showing a layout without sidebar for posts created with the old theme.

    Would be great if you could help me with that.
    Thanks in advance
    Richard

    #1587986
    David
    Staff
    Customer Support

    Hi there,

    looks like we can use this condition to determine if a page/post has WP Bakery enabled:

    https://kb.wpbakery.com/docs/inner-api/vc_enabled_frontend/

    So we could do this:

    1. Set the Customizer > Layout > Sidebars to NO SIDEBARS.

    2. Now Create a Layout Element that sets ALL posts to display a Sidebar. Make a note of the Elements ID whilst in the Element editor – you’ll find it in its URL.

    3. Then we can add this PHP Snippet to filter that layout element so it does not apply to WP Bakery pages:

    add_filter( 'generate_layout_element_display', function( $display, $element_id ) {
        if ( 10 === $element_id && vc_enabled_frontend() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    You need to change the 10 to ID of your layout element.

    #1588767
    Richard

    Hi David,

    thank you very much for this. Sounds like a smart solution.
    As far as I know vc_enabled_frontend() just returns true if the WPBakery FrontendEditor is activated, but I will follow your howto and make the post date the second condition.

    Have a great start into the new week.
    Richard

    #1589045
    David
    Staff
    Customer Support

    Glad to be of some help 🙂

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