2017-05-12 103 views
0

將我的joomla網站遷移到WP。這些圖像位於joomla網站的名爲「asets」的文件夾中。我將dir複製到wp和圖像工作正常,而url結構是原始的。 但是,如果我更改網址永久鏈接,圖像鏈接也會改變。WP圖像鏈接變更固定鏈接更改

like 
sitename/?p=123 image path = sitename/asets/imagefile this works. 

sitename/samplepost image path = sitename/post-name/asets/imagefile image not found 

sitename/archive/123 image path = sitename/archive/asets/imagefile image not found 

Please help me to solve this problem. 

回答

1

只需使用絕對路徑或相對路徑,在路徑開始處使用斜槓即可獲得根路徑。

我現在GUSS你的HTML代碼如下所示:

<img src="assets/imagefile.jpg" alt="" /> 

因此,它是一個相對路徑,瀏覽器將src添加到當前的URL。 但是,如果從根更改爲相對路徑是將工作:

<img src="/assets/imagefile.jpg" alt="" /> 

或使用完整的絕對路徑:

<img src="http://example.com/assets/imagefile.jpg" alt="" /> 

All about HTML file paths

更重要的事情,在WordPress你一定要僅在主題目錄範圍內工作並使用get_stylesheet_directory_uri()函數。

您的代碼需要看起來像這樣:

<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/imagefile.jpg" alt="" /> 
+0

這麼多的感謝。添加/之前的路徑工作。 – Jiban

+0

@Jiban請注意我最後提到的,根據WordPress代碼的規則,這非常重要。 –

+0

沒有注意到任何區別,但我按照你的說法做了。我有另一個問題。有什麼方法可以在wp評論中顯示youtube視頻嗎?我在網上找到了兩個插件「FitVids for WordPress」和「oEmbed in Comments」,但兩者都不起作用。仍然顯示的網址。 – Jiban