Add jQuery Mobile Internally

Hi there,

Site: https://fantasy-books.live
Wordpress: Latest
X Pro: Latest.

I’d like to add jQuery Mobile innately to the site as X Pro does with jQuery migrate. Any ideas how?

J.

Hi J,

Thank you for writing in, you can utilize the WordPress wp_enqueue_script() function.

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

Hope it helps,
Cheers!

Hi there,

So something like this for example? You have a recommendation on where to add it in my child theme? I’m looking for the best places as to reduce my CPU.

Ex. instead of using add_actions… i’ll just add things directly in the templates.

wp_enqueue_script(
‘jqm_js’,
‘http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js’,
array(‘jquery’),
‘1.2.0’
);
wp_register_style(
‘jqm_css’,
‘http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css

Hi J,

Loading script using the wp_enqueue_script() function is the right way. It does not affect your site’s performance anyway if you enqueue the script in the templates.

Please follow the example provided here (see the How to Properly Enqueue Scripts in WordPress section).

Add your custom functions on your child theme’s functions.php file. So it won’t be overwritten when an update is a release.

And watch out for the pretty quotes, on the code you showed above, those are pretty quotes (not regular quotes) that cause an error.

e.g.

wp_enqueue_script('my_amazing_script');

Hope it helps,
Cheers!

Thanks for the assist.

Hi @JfantasyBooks,

You’re most welcome.

Feel free to ask us again.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.