getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
634 stars 95 forks source link

Enqueue js/css files when view is loaded via shortcode #167

Closed aidanayala closed 7 years ago

aidanayala commented 7 years ago

I display my frontend UI when a shortcode is placed within a page.

How can I use enqueue to load the necessary js/css when this view / shortcode is used?

giwrgos88 commented 7 years ago

You can do the following and use the filter to load the js or css for the specific page that you use your shortcode

$enqueue->front([
    'as'  => 'postsJS',
    'src' => Helper::assetUrl('/js/post.js')
'filter' => [ 'panel' => ['mainPanel', 'subPanel'] ]
]);

for more reference

aidanayala commented 7 years ago

Thank you