Change script type and src of plugins in theme
Change script type and src of plugins in theme
Change script type and src of plugins in theme
Another option is to use the script_loader_tag filter to catch and remove the actual HTML tag before it is output, eg.: add_filter( ‘script_loader_tag’, ‘remove_social_login_frontend’, 10, 3 ); function remove_social_login_frontend( $tag, $handle, $src ) { if ( ‘wc-social-login-frontend’ === $handle ) {$tag = ”;} return $tag; } Note you could also do this via a string … Read more
The wp_add_inline_script() is designed for this purpose. It lets you add some inline JavaScript above or below an enqueued script. You just need to pass the contents of the script, without <script> tags: function custom_thing () { if ( is_page( 2138 ) ) { wp_enqueue_script( ‘external-script’, ‘http://domain.com/external/script.js’, array( ‘jquery’ ), 0, true ); wp_add_inline_script( ‘external-script’, … Read more
I’ll answer each of your questions in order: Do we care which scripts are enqueued? Not really. WordPress registers each script and maintains it in an array. When you enqueue the script, WordPress will load it and any dependencies it has when it calls wp_print_scripts() (which is tied to the wp_head hook). If you enqueue … Read more
Be sure about the parameters wp_enqueue_style and wp_enqueue_script uses.(The parameters are not same for both ) wp_enqueue_style( $handle, $src, $deps, $ver, $media ); you are giving false,false,true for dependency,version and media which is a blunder mistake.If you are not sure about them, you can avoid them and if you want to following is an example … Read more
Shortcodes are inconvenient for such things, because they are processed in content, way after site’s header. However since you don’t need to deal with styles, only a script, it’s a little easier by moving stuff to footer. Your logic would be something like following: Locale shortcode stores requested locale in some way. At some point … Read more
Masonry is already registered by WordPress. From wp-includes/script-loader.php: // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. $scripts->add( ‘masonry’, “/wp-includes/js/masonry.min.js”, array(), ‘3.1.2’, 1 ); $scripts->add( ‘jquery-masonry’, “/wp-includes/js/jquery/jquery.masonry$dev_suffix.js”, array( ‘jquery’, ‘masonry’ … Read more
From the enqueue point of view it doesn’t matter if it points to genuine static CSS file or endpoint that dynamically generates it. However there is a massive performance implication. Loading PHP engine (and worse — WordPress core on top) is much much more resource intensive than serving static file. Your end goal shouldn’t be … Read more
Your question is general, so I cannot answer it in details. If the parent theme enqueues some styles using get_stylesheet_directory_uri() in the path they won’t be available in child theme. Then you should enqueue lacking stylesheets in your child’s function.php using get_template_directory_uri() which will point to the parent theme directory. Some example: add_action( ‘wp_enqueue_scripts’, ‘wpse179217_enqueue_styles’ … Read more
You can use init action to set cookie, and other init action to read it. However due its a cookie… you will need also to check GET variable. add_action(‘init’, ‘is_it_mobile_or_desktop’, 1); function is_it_mobile_or_desktop(){ if (isset($_GET[‘site’]) && in_array($_GET[‘site’], array(‘mobile’, ‘desktop’)) ) { setcookie( ‘site’, $_GET[‘site’], time() – YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); } } add_action(‘init’, ‘who_am_i’, 2); … Read more