0

Firstly, I build wordpress with domain localhost. Now I change the domain to abc.ddns.net. However, both the css and image cannot be loaded. I inspect the element, and found the 404 of these resource. How can I change the URL to abc.ddns.net.

Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost/wp-content/themes/sumo/style.css?ver=4.1.1
GET http://localhost/wp-content/themes/church/js/tinynav.js?ver=4.1.1  kcfmchk.ddns.net/:16
GET http://localhost/wp-content/themes/church/images/header.jpg 404 (Not Found) kcfmchk.ddns.net/:41
GET http://localhost/wp-content/themes/church/style.css?ver=4.1.1  kcfmchk.ddns.net/:13
GET http://localhost/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1  kcfmchk.ddns.net/:15
GET http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1  kcfmchk.ddns.net/:14
GET http://localhost/wp-content/themes/church/images/header.jpg 404 (Not Found) 
0

There's possible a couple different things going on, so here's a relatively generic answer.

Site URL

Many URLs are influenced by the Site URL settings in Settings > General. The steps for properly moving a site are too long for a single answer, but review the "Changing the Site URL" codex page and make sure you've covered all the steps.

WordPress API URL Functions

For things like stylesheets and scripts, you should be using wp_enqueue_style() and wp_enqueue_script() to load them. However, you still need to know the locations of files. That's where get_template_directory_uri(), get_stylesheet_directory_uri(), plugins_url(), and other similar functions come in. They'll return the correct URLs based on the Site settings (above) so that when you move the site, the srcs for all resources are updated.

An example:

add_action( 'wp_enqueue_scripts', 'wpse183676_enqueuer' );
function wpse183676_enqueuer() {
    wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/myscript.js' );
}

Bundled Scripts

Finally, go one step further, there are many scripts that come with WordPress so you don't need to provide your own copy or even know where the specific files are. Just use the correct handle for any of the scripts bundled with WordPress and they'll automatically load.

In the simplest form, that would look like this:

add_action( 'wp_enqueue_scripts', 'wpse183676_enqueuer' );
function wpse183676_enqueuer() {
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/myscript.js' );
}

However, we can accomplish the same results even faster by using the $dependencies argument of wp_enqueue_script() like this:

add_action( 'wp_enqueue_scripts', 'wpse183676_enqueuer' );
function wpse183676_enqueuer() {
    wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/myscript.js', array( 'jquery' ) );
}
  • Did it answer your question? – mrwweb Apr 9 '15 at 4:27
  • Yes So nice for you – want_to_be_calm Apr 9 '15 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.