2017-09-02 78 views
0

我使用我的wordpress網站的xampp製作了本地副本。主題是我寫的。 在本地,使用get_template_directory_uri()或get_stylesheet_directory_uri()的每個圖像鏈接都會因爲缺少「http」前綴而中斷。如果我手動添加它,則圖像顯示正確。get_stylesheet_directory_uri()和get_template_directory_uri()不返回「http」

這是代碼: <?php echo get_stylesheet_directory_uri() . '/images/myimage.jpg' ?>

上述功能在線產生:
http://www.mywebsite.it/wp-content/themes/mytheme/images/myimage.jpg"
本地上XAMPP他們產生:
localhost/myfolder/wp-content/themes/mytheme/images/myimage.jpg
,並且不顯示圖像。如果我手動添加http://之前localhost它的作品。

有趣的是,函數get_template_directory_uri()也被用在functions.php中以排列一些樣式表,並且它在那裏生成正確的以http開頭的url,即使在本地也是如此。

我不知道很難解決這個問題,我不想在本地更改每個鏈接,並且必須記住在將它放到網上之前修復它。對不起我的英語不好。

編輯:我是能夠自動添加「HTTP」,由逃逸的URL,這個代碼
<?php echo esc_url(get_stylesheet_directory_uri() . '/images/myimage.jpg') ?>
這在當地解決了這個問題,並且不在線影響輸出,所以我可以同步像代碼這......仍然,我不知道爲什麼它會這樣。

+0

有什麼錯在這裏。我多次使用localhost並從未遇到過這個問題。您的網站是否添加了任何'stylesheet_directory_uri','theme_root_uri'或'content_url'過濾器? – user8262086

+0

@ user8262086不,它不是 – Oromis

回答

1

請檢查的WordPress地址(URL)網站地址(URL)設置

+0

它們都是'http:// localhost/mysite' – Oromis