Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marklchaves/891586c49231889f86601f366d8c136c to your computer and use it in GitHub Desktop.
Save marklchaves/891586c49231889f86601f366d8c136c to your computer and use it in GitHub Desktop.
Tell GenerateBlocks about Popup Maker's custom post type so GenerateBlocks can scan the popup content and spit out the dynamic CSS it needs
<?php // Ignore this first line when copying to your child theme's functions.php file.
/*
* This solution should be the accepted answer in this forum thread.
*
* https://generatepress.com/forums/topic/gpgbpopup-maker-issue/#post-2088153
*/
add_filter( 'generateblocks_do_content', function( $content ) {
$post_id = 467; // Change to your Popup Maker popup ID https://docs.wppopupmaker.com/article/409-find-the-popup-id
if ( has_blocks( $post_id ) ) {
$block_element = get_post( $post_id );
// Where 'popup' is the custom post type for Popup Maker popups.
// The original text from the GenerateBlocks doc is 'your_post_type'
// https://docs.generateblocks.com/article/adding-content-sources-for-dynamic-css-generation/
if ( ! $block_element || 'popup' !== $block_element->post_type ) {
return $content;
}
if ( 'publish' !== $block_element->post_status || ! empty( $block_element->post_password ) ) {
return $content;
}
$content .= $block_element->post_content;
}
return $content;
} );
/**
* You can add the PHP code snippet to your child theme's functions.php file
* or with third-party plugins such as My Custom Functions and Code Snippets.
*
* Learn more:
* - https://docs.wppopupmaker.com/article/84-getting-started-with-custom-js
* - https://docs.wppopupmaker.com/article/552-getting-started-with-custom-php
*/
@marklchaves
Copy link
Author

Before and After demo

Before and after turning on the generateblocks_do_content filter.

popup-maker-generateblocks-filter-demo

@Fortyfive
Copy link

Hi Mark, great solution - just wondered if you'd be able to advise on how to amend this to look for any one of 6 popup IDs all on the same page? Thanks! David

@marklchaves
Copy link
Author

Hi @Fortyfive ,

Hi Mark, great solution - just wondered if you'd be able to advise on how to amend this to look for any one of 6 popup IDs all on the same page? Thanks! David

Much appreciated. I can't take credit. That code is from GenerateBlocks help doc 😉

Do you mean, "How can you make this work for multiple popups?"

If so, I asked the GB team to support that a few months ago. They gave a workaround. Give it a try if that's what you're looking for.

https://wordpress.org/support/topic/calling-generateblocks_do_content-with-a-post-id-argument/#post-17405211

Cheers!

@Fortyfive
Copy link

Fortyfive commented Jul 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment