Created
March 5, 2026 07:54
-
-
Save devAsadNur/9ed3ee9590adfce81623866e0181bc28 to your computer and use it in GitHub Desktop.
Popup critical css generation by force
This file contains hidden or 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
| /** | |
| * Add popup/library content to Divi 5 dynamic CSS detection. | |
| * | |
| * This allows Divi to detect modules used inside popup CPT layouts | |
| * so their CSS is included in the dynamic CSS file (et-divi-dynamic.css). | |
| * | |
| * @param string $content Content string used by Divi to detect modules. | |
| * @return string Modified content with popup layouts appended. | |
| */ | |
| function df_add_popup_content_to_dynamic_css_detection( $content ) { | |
| // Only run on frontend and when Divi 5 dynamic assets system exists | |
| if ( is_admin() || ! class_exists( 'ET\Builder\FrontEnd\Assets\DynamicAssets' ) ) { | |
| return $content; | |
| } | |
| static $popup_content_cache = null; | |
| // Use cached content if already built | |
| if ( null !== $popup_content_cache ) { | |
| return $content . ' ' . $popup_content_cache; | |
| } | |
| $popup_posts = get_posts( [ | |
| 'post_type' => 'difl_popup', | |
| 'posts_per_page' => -1, | |
| 'post_status' => 'publish', | |
| 'fields' => 'ids', // performance optimization | |
| ] ); | |
| if ( empty( $popup_posts ) ) { | |
| return $content; | |
| } | |
| $popup_contents = []; | |
| foreach ( $popup_posts as $post_id ) { | |
| $post_content = get_post_field( 'post_content', $post_id ); | |
| if ( ! empty( $post_content ) ) { | |
| $popup_contents[] = $post_content; | |
| } | |
| } | |
| if ( ! empty( $popup_contents ) ) { | |
| $popup_content_cache = implode( ' ', $popup_contents ); | |
| $content .= ' ' . $popup_content_cache; | |
| } | |
| error_log($content); | |
| return $content; | |
| } | |
| add_filter( | |
| 'divi_frontend_assets_dynamic_assets_content', | |
| 'df_add_popup_content_to_dynamic_css_detection', | |
| 10, | |
| 1 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment