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

How to enqueue JavaScript in a simple way. #598

Open
drozumek opened this issue Sep 11, 2019 · 3 comments
Open

How to enqueue JavaScript in a simple way. #598

drozumek opened this issue Sep 11, 2019 · 3 comments
Labels
documentation Issue in documentation or videos javascript php question Further information is requested

Comments

@drozumek
Copy link

drozumek commented Sep 11, 2019

Issue Overview

Is really enqueue of JS files that complicated as shown in that tutorial
https://www.linkedin.com/learning/wordpress-building-progressive-themes-with-wp-rig-2/enqueue-javascript-files
?
I've been using WP Rig for building websites for a long time, but now when I switch to version 2.0 I have the impression that building process is more complicated in some ways.

How can I enqueue simple js file, for example, "scripts.js" with alert( 'test' ) which show on all pages? The tutorial from the link above, with components, drives me crazy.

In WP RIG 1 you could do that in functions.php

What is the best way to just enqueue js file to my website build with WP RIG 2.0?
I think the way it is presented by Morten in that course linked above only increases entry-level to build themes using this tool.

@justlevine
Copy link

I cant find the nonpaywalled version of that video, but wp_enqueue_script still works no matter where you place it.

Best practice would be to either create something like inc/Scripts/Component.php, or if its related to a specific feature in your theme, then include it there (for an example, see inc/Lazyload/Component.php line 135).

But you could also just create a public function action_enqueue_theme_scripts() in inc\Base_Support\Component.php and be done with it.

(Regardless of where you do it, just remember to hook the function in initialize(), not after the enqueue function definition).

@benoitchantre benoitchantre added javascript php question Further information is requested labels Oct 3, 2019
@jchck
Copy link

jchck commented Nov 21, 2019

This seems like the sort of thing that could be addressed with an improvement to the docs and a working example in the code, similar to how CSS is treated.

@kunstudios
Copy link

I would love an example too. I'm just trying to hook into masonry included in WP and can't do it the regular functions way

@jacklowrie jacklowrie added the documentation Issue in documentation or videos label Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issue in documentation or videos javascript php question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants