Tag Info

New answers tagged

0

You can also leave off the protocol, like this: wp_enqueue_style( 'be-fonts', '//fonts.googleapis.com/css?family=Ubuntu:300,400,500' );


1

Building on the accepted answer and filling in some details... You need to call wp_localize script right after wp_enqueue_script. So, something like this: function my_enqueue_scripts() { wp_enqueue_script( 'myjs', plugins_url( 'js/my.js', __FILE__) ); $options = get_option( 'my_settings' ); $scriptData = array( ...


0

Yes this is fine and is a good practice, especially if your site may switch between HTTPS/HTTP (like for a shopping cart etc) that way you are not loading mixed content. As long as the CDN you are pulling from offers both HTTPS and HTTP you're fine, which they do.


0

If you want to enqueue your files separately use this code and still be able to register them(probably you want to use it after wards as well) then use this: $template_directory = get_template_directory_uri(); $array_of_js_files = array( array( 'script_handle1', $template_directory . '/your_directory/file1.js', array(), //any ...


3

You need to enqueue the scripts as well, not only register them. You can, however, just simply enqueue a script without registering it if you are not going to enqueue it conditionally. I would try something like this: (Untested and requires PHP5.4+) add_action( 'wp_enqueue_scripts', enqueue_scripts, 11 ); function enqueue_scripts() { /** * Build ...


2

Thank you for your post, mrwweb. I found another solution to this, by creating a very simple plugin you can deactive when the site is no longer under development. <?php /* Plugin name: Strip WP Version in Stylesheets/Scripts */ function switch_stylesheet_src( $src, $handle ) { $src = remove_query_arg( 'ver', $src ); return $src; } ...


1

EDIT: If you use $post in a function, you have to define it of course: function xyz(){ global $post; //Your code } Initial answer, might help others: It appears to me, you do not use it inside an action or if so, you use it to early. It should work inside the 'init' action. So you could do something like <?php add_action( 'init', ...


0

I found the problem.... I ran main.php like: function run_this(){ include'path/to/other.php'; } add_shortcode('shortcode', 'run_this'); And most of the content of other.php came up exept the hooks did'nt work then i tried using add_action('init', 'run_this'); and then it worked.... exept that i get a fatal error that i cant redeclare some functions ...


0

You have to place the enqueue code with in a function and use add_action to call the function where you register. Like below add_action( 'wp_enqueue_scripts', 'your_function_name', 10 );


0

If you are registering the styles/scripts, then you will be setting all the parameters at that point. No need to pass them all again when enqueuing - by then you will only need to pass the handle. If you are definitely only going to call your styles/scripts in one place, then you can skip the registration entirely. Instead, just enqueue, and pass all the ...


6

First of all this is what I use and for me and it works. I'm not saying that my code is 100% correct but Pingdom as well GTmetrix show a positive effect and WP is satisfied also, so it can't be that wrong as I do. The versions showing (?ver=x.x.x) can be debet when those files need to be cached so stripping(filter) that is already a first step. The code ...


1

Here was the problem. I just didn't add the <?php wp_footer(); ?> in my footer.php file. so simple but important. I guess woocommerce group should check if wp_footer() doesn't exists add the scripts in header instead because I have wp_head() set up in my header.php


0

This works for me: function register_my_css () { wp_register_style('my-style', plugins_url('styles.css', __FILE__)); } function register_my_scripts () { wp_register_script('my-script', plugins_url('scripts.js', __FILE__)); } // only enqueue the scripts / styles when the short code is called function do_my_shortcode () { ...


1

Well after a bit of better searching i found the answer, function my_enqueue($hook) { if ( 'settings_page_data-layer-management' != $hook ) { return; } wp_enqueue_script( 'my_custom_script', plugins_url( 'js/dlm-window.js', __FILE__ )); } add_action( 'admin_enqueue_scripts', 'my_enqueue' ); to explain just incase anyone has this ...


1

01. Change if (($site == 'desktop'){ // code line } TO if (($site == 'desktop') && (wp_is_mobile())) { // code line } 02. and for unset the cookie while the browser is closed give the time as 0 (zero) or blank. some thing like this. setcookie( 'button_clicked', $_GET['button_clicked'], 0, COOKIEPATH, COOKIE_DOMAIN);


0

Short Answer: Yes, but... Just make sure your call to wp enqueue script is before the call to get_header(). The problem is that when you're in a later part of your template the header including the script is already sent to the browser so you can't change it any more. While this is possible I'd still encourage you to reconsider and put this in the ...


0

I was wondering the same thing. There's a modern version that uses admin_enqueue_scripts: add_action('admin_menu', function () { $settingsPage = add_options_page('Settings', 'Mortgage Calculator', 'manage_options', 'mortgagecalculator', function () { echo "<div id='app'></div>"; }); /** * Include the ember admin scripts only on ...



Top 50 recent answers are included