最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - get_template_directory_uri() generates wrong path

programmeradmin0浏览0评论

I've uploaded a wordpress site but it's missing javascript and css. The links on the head still have the local path (src='https://localhost...') and not the new ones. So I guess it has to do with get_template_direcory_uri() that I use in fucntions.php to apply my javascript/jquery,bootstrap,css etc.

How yo fix that?

I've tried adding to config.php:

define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_HOME',    'http://' . $_SERVER['HTTP_HOST'] );

and

define( 'WP_HOME', 'https://...' );
define( 'WP_SITEURL', 'https://...' );

but they didn't help...

I've uploaded a wordpress site but it's missing javascript and css. The links on the head still have the local path (src='https://localhost...') and not the new ones. So I guess it has to do with get_template_direcory_uri() that I use in fucntions.php to apply my javascript/jquery,bootstrap,css etc.

How yo fix that?

I've tried adding to config.php:

define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_HOME',    'http://' . $_SERVER['HTTP_HOST'] );

and

define( 'WP_HOME', 'https://...' );
define( 'WP_SITEURL', 'https://...' );

but they didn't help...

Share Improve this question edited Oct 28, 2019 at 12:59 kero 6,3401 gold badge25 silver badges34 bronze badges asked Oct 28, 2019 at 12:33 Emmanuel RichmanEmmanuel Richman 134 bronze badges 4
  • Can you show how you enqueue your styles and scripts? Please make sure to use formatting, you can see how to do it from my edit – kero Commented Oct 28, 2019 at 12:59
  • Have you updated the all of your site links after the migration? Please show us your enqueue code – Arsalan Mithani Commented Oct 28, 2019 at 13:11
  • Have you set the correct URL in Settings > General? – Jacob Peattie Commented Oct 29, 2019 at 5:40
  • I have the same problem. In a development environment I want to use settings different from those in wp_options table. In the back end I do see the grayed out versions of site_url and home conforming the setting in wp_config.php. However, get_template_directory_uri() just returns the one in wp_settings, not the one in wp_config.php. – th00ht Commented Apr 14, 2020 at 9:32
Add a comment  | 

1 Answer 1

Reset to default 1

Do your URL change up in phpMyAdmin with SQL language:

# Change website url
UPDATE wp_options
SET option_value = replace(option_value, 'http://www.old-site','http://www.new-site') WHERE option_name = 'home' OR option_name = 'siteurl';

# Change GUID URL
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.old-site','http://www.new-site');

# Change url of medias, post, page, etc.
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.old-site','http://www.new-site');

# Change meta data url
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.old-site','http://www.new-site');
发布评论

评论列表(0)

  1. 暂无评论