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

Best practices for running scripts #20

Open
steveadamsfixedit opened this issue Aug 23, 2021 · 1 comment
Open

Best practices for running scripts #20

steveadamsfixedit opened this issue Aug 23, 2021 · 1 comment
Labels

Comments

@steveadamsfixedit
Copy link

I've used the boilerplate to create a custom plugin to track user engagement analytics on live streamed video assets. included in the plugin within the /public directory are some fairly robust JavaScripts that mesh with a webhook from the stream provider and a AJAX call to track real time player events.
It's my understanding that these scripts added to the enqueue_scripts() function in the public/class-plugin-name-public.php run on every single page in the rather vast WP site I'm intending to deploy it on. This seems inefficient and rather insecure...
What's best practice as far as only getting the scripts to run on specific pages...for instance, making a custom theme template and only applying that template file to a page containing video assets?

@GaryJones
Copy link
Owner

For front-end JS, you can conditionally enqueue with https://developer.wordpress.org/themes/basics/conditional-tags/, and for admin pages, you can check against get_current_screen().

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

No branches or pull requests

2 participants