How to enqueue extension style only in the page with Layers widget?

Asked on July 25, 2015 in Development.

Hi all,

I am developing a Layers extension. This extension will enqueue different style file based on user’s settings in customizer.
Here is my question:
1.Is it possible to enqueue the extension style only in the page that contains my Layers widget?
2.Is it possible to enqueue the extension style in HTML ?

ucheng Developer
Reply
  • Possible Answers to Your Question:

  • 1 Answer(s)
    Answered on August 24, 2015. Best answer

    Hello,

    1. That would be extremely tricky as there is no core condition that can look at something like a widget ID, which is all that can distinguish that page from the rest. I recommend using layers_inline_styles to properly add styling that goes with your widget to the page, which is how we do it. You can also add the enqueue itself to the widget class so it only fires if the widget is loaded.

    2. No, you can only enqueue via wp_enqueue_styles hook which requires a PHP function.

    https://docs.layerswp.com/plugin-creation-guide/#including-scripts-styles%c2%a0-php

    Vail Joy Layers Team
    Reply