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
*/
@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