Enqueue plugin for specific pages
It started to work once i change add_action( ‘init’, ‘my_enqueue’ ); to add_action( ‘wp_enqueue_scripts’, ‘my_enqueue’ );
It started to work once i change add_action( ‘init’, ‘my_enqueue’ ); to add_action( ‘wp_enqueue_scripts’, ‘my_enqueue’ );
Issue 1 I was not seeing the embedded object in javascript because: The error was, I thought plugins_url always resolved to the plugins dir, it resolves to the dir of __FILE__: In my situation myplugin.js and myplugin.php are both in the same public/ dir, so this: $script_url = plugins_url( ‘public/myplugin.js’, __FILE__ ) Was resolving as … Read more
Do not use “about” as handle as it seems to be not unique and used by WordPress itself. I don’t see the list of style handles is documented somewhere. Anyway, use something unique like ‘rejaur-about’: <?php function load_page_styles() { if ( is_front_page() ) { // enqueue front page styles } elseif ( is_page(‘about’) ) { … Read more
You’re using the wrong hook to enqueue your styles: add_action(‘admin_enqueue_scripts’, ‘seizoenplugin_enqueue_styles’ ); As the name suggests, admin_enqueue_scripts is for enqueuing scripts and styles in the admin. To enqueue scripts on the front end use wp_enqueue_scripts: add_action(‘wp_enqueue_scripts’, ‘seizoenplugin_enqueue_styles’ );
Get with jQuery the value of an ACF field
You’ve tagged your question correctly with wp_enqueue_script but it doesn’t appear in your code so you are probably missing the jQuery library and bootstrap by the looks of it. Try adding the following: add_action(‘wp_enqueue_scripts’, ‘wp_add_jquery’); function wp_add_jquery () { wp_register_script( ‘my_jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js’); // Add your other scripts here (bootstrap, etc.) }
Seeing as your aim is to improve loading on the front end, the best approach would be to simply not add the defer attribute when loading in the admin area, like so. add_filter( ‘script_loader_tag’, function ( $tag, $handle ) { if ( ‘jquery-core’ !== $handle ) { return $tag; } if ( ! is_admin() ) … Read more
Is it possible to load recaptcha script only in url with fragment identifier (#)?
How to do chunked JS files in WordPress?
What are you hooking public function enqueue_scripts() on to? You might need to use add_action( ‘admin_enqueue_scripts’, array( ‘Your_Class’, ‘enqueue_scripts’ ) );