Add CSS code snippet for MailPoet?

On Mailpoet support there is a post about 3rd party CSS conflicts
( How to Solve 3rd-party CSS Menu Conflict - MailPoet Knowledge Base

I have the Code Snippets extenssion installed but I see no way to add code to “scripts” and “styles” as instructed by MailPoet’s support post. I think it is maybe only a Code Snippets Pro option?

Is there a way to do what is instructed by MailPoet using MainWP?

Both are PHP code snippets, that need to be run always, so you can add them to a site using the Code Snippets extension and selecting the “Execute on Child Sites” option. That way the snippets will be saved in the database of the child site and executed like they were included in the theme’s functions.php.

Just test it with one site, before you add the snippets to all sites you need it on.

2 Likes

Hey @Gary_Petro

The advice given by @josklever is correct. When a snippet is added using Code Snippets extension with the “Execute on Child Sites” option, it is equivalent as being written in the theme’s functions.php file.

The only difference is that when using our extension, the snippet will be written in the database, and it will be executed automatically as long as the MainWP Child plugin is active on the child site.

1 Like

After I do this for the code provided by MailPoet on a single site I get " MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the MainWP Community for help."

Only after unloading the snippet can I get the site up again. I copied and pasted the code and changed what I was instructed to but can’t get the snippet to work.

1 Like

Can you post a screenshot from the snippet on your Code Snippets screen, so we can check if we see any errors?
And did you check the error log on the child site to see if some errors were logged during this test?

1 Like

Please share the exact snippet (or post a screenshot as @josklever ) suggested that you’re using in the extension.

Have you tried any other snippets using the Code Snippets extension?

And have you tried saving that MailPoet snippet manually in the theme’s functions.php file?

Snippet:

Error log:

23-Jan-2024 00:11:22 UTC PHP Parse error: syntax error, unexpected token “<” in /home0/terrautopia/public_html/wp-content/plugins/mainwp-child/class/class-mainwp-utility.php(96) : eval()'d code on line 5
22-Jan-2024 21:43:45 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
22-Jan-2024 21:43:45 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
22-Jan-2024 21:43:36 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
22-Jan-2024 21:43:36 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
22-Jan-2024 21:41:58 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
22-Jan-2024 21:41:58 UTC PHP Warning: Undefined property: stdClass::$plugin in /home0/terrautopia/public_html/wp-includes/class-wp-list-util.php on line 168
thrown in /home0/terrautopia/public_html/wp-content/plugins/mailpoet/lib/Config/Initializer.php on line 466

I have used other snippets without issues.

Have not yet tried adding it manually to theme’s functions.php.

Thanks.
Gary

I figured it out.
Changed the code snippet for this and it works:
add_filter(‘mailpoet_conflict_resolver_whitelist_script’, function ($scripts) { $scripts = ‘wp-simple-firewall’; return $scripts;});
add_filter(‘mailpoet_conflict_resolver_whitelist_style’, function ($whitelistedStyles) { $whitelistedStyles = ‘wp-simple-firewall’; return $whitelistedStyles;;

2 Likes

The color highlighting of the code already gave it away. the <br> tags were copied instead of actual line breaks. Always be careful when copying code from other sources that are not using plain text or preformatted text.

Tip for the next time you paste code here or on other forums, use the preformatted styling or a code block (if available). :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.