Support » Plugin: Elementor Website Builder » Force enqueue Elementor scripts and styles on AJAX site

  • Hi there,

    Since my site’s page content is loaded via AJAX wp_head() is only executed on the first page load and Elementor’s assets are sometimes not enqueued when needed, since not all pages use Elementor.

    Best thing I can think of is to make sure Elementor scripts and styles are enqueued on every page load, or ideally conditionally on pages I know will need them.

    This seems to work: I add the following to the wp_enqueue_scripts hook.

    $elementorFrontend = new \Elementor\Frontend();
    $elementorFrontend->enqueue_scripts();
    $elementorFrontend->enqueue_styles();

    Is this future proof? Is there a better way of doing this?

    Many thanks,

    Simon

    • This topic was modified 3 years, 4 months ago by simooo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Update: it *almost* works – the stylesheet for individual posts isn’t loaded.

    So for example for a post with ID 6 the stylesheet post-6.css should be loaded but isn’t.

    Is there a hook for this?

    Yes. How should this be done?
    I’m loading page content through shortcodes and would like to push the required files to the client.
    Ideally through a setting but that would be a new feature.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Force enqueue Elementor scripts and styles on AJAX site’ is closed to new replies.