Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divi integration breaks certain Divi module(s) in the Divi visual builder #265

Open
jonmarkhall opened this issue Feb 9, 2024 · 1 comment

Comments

@jonmarkhall
Copy link

The add_et_tag() function in this plugin's Divi integration prevents loading of various scripts in the Divi visual builder by adding the et_fb_ignore_iframe class to their script tags:

return '<script type="text/javascript" src="' . $src . '" class="et_fb_ignore_iframe"></script>' . "\n"; // phpcs:ignore

This breaks some Divi module(s) that depend on these scripts being loaded in the visual builder. Notably, Divi modules that rely on the WordPress script i18n API for translation functions (provided by the wp-i18n script) may crash without this script; however, there are probably also other problems caused by preventing core JavaScript files from loading in the visual builder.

@jonmarkhall jonmarkhall changed the title Divi integration breaks certain Divi modules in the Divi visual builder Divi integration breaks certain Divi module(s) in the Divi visual builder Feb 9, 2024
@divibooster
Copy link

divibooster commented Jan 4, 2025

Thanks for sharing this @jonmarkhall - it was very helpful. I encountered the same issue on one of my modules which relies on wp-i18n. I was able to work around it by capturing the tag prior to Rankmath's modification and restoring it again afterwards, with this code:

class PreventTagModification {

    private $tag;
    private $handle;

    public function __construct($handle) {
        $this->handle = $handle;
    }

    public function init() {
        add_filter('script_loader_tag', array($this, 'before_modification'), 9, 3);
        add_filter('script_loader_tag', array($this, 'after_modification'), 11, 3);
    }

    public function before_modification($tag, $handle, $src) {
        if ($handle === $this->handle) {
            $this->tag = $tag;
        }
        return $tag;
    }

    public function after_modification($tag, $handle, $src) {
        if ($handle === $this->handle) {
            return $this->tag;
        }
        return $tag;
    }
}

$preventTagModification = new PreventTagModification('wp-i18n');
$preventTagModification->init();

It would be nicer, though, if Rankmath either adds 'wp-i18n' to the excluded handles in add_et_tag(), or adds a filter to the exclusions list so that we can add our own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants