Created
April 3, 2023 12:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
*/ |
<!--
/* Font Definitions */
@font-face
{font-family:Courier;
panose-1:2 7 3 9 2 2 5 2 4 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
{font-family:"Apple Color Emoji";
panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
-->Thanks Mark : ) From: mark l chaves ***@***.***>Date: Thursday, 4 July 2024 at 00:50To: marklchaves ***@***.***>Cc: Mention ***@***.***>Subject: Re: ***@***.*** commented on this gist.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! DavidMuch 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-17405211Cheers!—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you were mentioned.Triage notifications on the go with GitHub Mobile for iOS or Android.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Fortyfive ,
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!