Add attribute to script loaded by the theme

The code referenced in your question is still good. I double checked, and this worked for me: function wpse_script_loader_tag( $tag, $handle ) { if ( ‘jquery-fluidbox’ !== $handle ) { return $tag; } return str_replace( ‘ src’, ‘ data-cfasync=”false” src’, $tag ); } add_filter( ‘script_loader_tag’, ‘wpse_script_loader_tag’, 10, 2 ); (I tested with a different script … Read more

add mediaelement.js plugins into WordPress video player control bar

You can alter the mediaelement.js feature-set using the mejs_settings hook. Settings Overview Defaults are: playpause, current, progress, duration, tracks, volume, fullscreen. Add the plugin to the array as needed to extend the features. add_filter(‘mejs_settings’, function ($settings) { $settings[‘features’] = array(…,’jumpforward’); return $settings; }); Make sure to enqueue the plugin itself: wp_enqueue_script( ‘mejs-plugin-name’, ‘path_to_plugin_file’, array(‘wp-mediaelement’), null, … Read more

wp_is_mobile dequeue not working

It looks like you are using the script “src” rather than the script “handle”. Have you tried: add_action( ‘wp_enqueue_scripts’, ‘remove_plugin_scripts’, PHP_INT_MAX ); function remove_plugin_scripts() { if ( wp_is_mobile() ) { // Remove script file. wp_dequeue_script( ‘tp-tools’ ); wp_deregister_script( ‘tp-tools’ ); wp_dequeue_script( ‘revmin’ ); wp_deregister_script( ‘revmin’ ); } }

Simple Plugin with custom javascript wont work – no console error

You could “borrow” the html form from the example and include this in your template – either directly of via a filter like wp_footer: <form method=”GET” action=”/javascript/search-highlight/” onsubmit=”myHilitor.apply(hilite.value); return false;”> <fieldset> <legend>Highlight Words</legend> <label>Keywords</label><span><input type=”text” size=”32″ name=”hilite” value=”search engine keywords”> <input type=”submit” value=”Apply”> <input type=”button” value=”Remove” onclick=”myHilitor.remove();”></span> </fieldset> </form>

How do I display a user’s previous orders as a select box option on a product?

You can try something like this: add_action( ‘woocommerce_before_add_to_cart_form’, ‘add_list_completed_orders’ ); function add_list_completed_orders() { // get orders $orders = wc_get_orders ( array ( ‘status’ => array( ‘wc-completed’ ), ‘type’ => ‘shop_order’, ‘limit’ => -1, ‘return’ => ‘ids’, ‘customer_id’ => get_current_user_id(), ) ); if ( ! empty( $orders ) ) { // set value options $options=””; foreach … Read more

Replace menu links with # and add name to its li

I want the URLs of the nav-items to be replaced with # You can use the nav_menu_link_attributes hook to set the custom href value like so: add_filter( ‘nav_menu_link_attributes’, function ( $atts, $item, $args ) { if ( ‘menu-categorias’ === $args->theme_location && ‘category’ === $item->object ) { $atts[‘href’] = ‘#’ . get_term_field( ‘slug’, $item->object_id ); } … Read more

Using wp.data.select get actual tags (not id’s) used in post

You can use getEntityRecord() like so: const tag_ids = wp.data.select( ‘core/editor’ ).getEditedPostAttribute( ‘tags’ ); // the last parameter is always the tag ID (and just one single ID) const tag = wp.data.select( ‘core’ ).getEntityRecord( ‘taxonomy’, ‘post_tag’, tag_ids[0] ); console.log( tag ? tag.name : ‘still resolving or no such tag..’ ); Or use getEntityRecords() with the … Read more

Convert HTML Script to Shortcode [closed]

Your JavaScript targets a HTML element with the id ‘banner_div’. So the first step is to output such an element in the shortcode. add_shortcode( ‘shortcode_name’, function () { $out=”<div id=”banner_div’></div>’; return $out; } ); Now you need to save the JavaScript (everything between the <script> tags) as a file. This you can now enqueue which … Read more