0
votes

I am newbie of wordpress.

There are always some JS and Css from CDN in Wordpress, theme or plugins, like:

https://ajax.googleapis.com/ajax/libs/webfont/1.5.0/webfont.js

https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css

Unfortunately, those external CDNs resource are quite slow in our country, and will caused our site serious delay.

Is there anyway to replace it with a local server copy please?

How should I do it please?

Thanks in advance.

2

2 Answers

0
votes

One solution you got in comments that how to load jQuery locally and in case you have any other scripts or styles which are not available locally by default from WordPress so you can use wp_enqueue_script.

/** * Proper way to enqueue scripts and styles. */

function wpdocs_theme_name_scripts() {

wp_enqueue_style( 'style-name', get_stylesheet_uri() );

wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );

}

add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );`

0
votes

Well you can always override your current themeto enqueue your css and js. Basically go to :

wordpress/wp-content/themes/(the theme your using)/functions.php

You will need to modify the "functions.php" file and add an action in order to enqueue your new scripes and styles.

function mynew_scripts() {
wp_enqueue_script('webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.0/webfont.js');
wp_enqueue_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css');

//And for local file use get_template_directory_uri() to get the path
wp_enqueue_script('yourjsfile',get_template_directory_uri().'/yourthemedir/assets/js/yourjsfile.js');
wp_enqueue_style('yourcssfile',get_template_directory_uri().'/yourthemedir/assets/js/yourcssfile.css');


}

add_action('wp_enqueue_scripts', 'mynew_scripts');

check up these functions wp_enqueue_script , wp_enqueue_style