2016-07-21 88 views

回答

2

模板URI

要獲得當前活動的主題目錄URI,使用get_template_directory_uri()。例如:

<?php 
$directory_uri = get_template_directory_uri(); 

$my_file = $directory_uri . '/images/path/to/img.jpg'; 

查看官方文檔here

模板路徑

要獲得當前活動主題的目錄路徑,使用get_template_directory()

<?php 
$directory_path = get_template_directory(); 

$my_file = $directory_path . '/images/path/to/img.jpg'; 

官方文件here。主題和模板之間

差異

請注意,這兩個函數將返回URI或活動模板的路徑,這意味着,如果你使用一個子主題,然後父主題的網址或路徑將被退回。如果它不是兒童主題,則只返回當前主題的URL或PATH。

如果您使用的是兒童主題並希望獲取當前兒童主題的參考,請改爲使用get_stylesheet_directory_uriget_stylesheet_directory

獲取值的任何主題

如果你的主題不是活動之一,那麼你就需要使用get_theme_root_uriget_theme_root代替。

+0

謝謝你的回答!祝你有美好的一天! :) –

相關問題