下一個解決方案不喜歡我,但是是一個選項:
去 'WP-包括/一般的template.php' 文件,並添加:
$templates = apply_filters('replace_header', $templates);
在get_header功能最終的結果功能是:
function get_header($name = null) {
/**
* Fires before the header template file is loaded.
*
* The hook allows a specific header template file to be used in place of the
* default header template file. If your file is called header-new.php,
* you would specify the filename in the hook as get_header('new').
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific header file to use.
*/
do_action('get_header', $name);
$templates = array();
$name = (string) $name;
if ('' !== $name) {
$templates[] = "header-{$name}.php";
}
$templates[] = 'header.php';
$templates = apply_filters('replace_header', $templates); //This is the new line.
locate_template($templates, true);
}
而在這之前,你可以取代所有模板:
function prefix_new_header($templates) {
return 'header-newtmpl.php';
}
add_filter('get_header', 'prefix_new_header');
或只加你:
function prefix_new_header($templates) {
$templates[] = 'header-newtmpl.php';
return $templates;
}
add_filter('get_header', 'prefix_new_header');
我從來沒有修改源代碼,我只把這裏一個解決問題的辦法。
的行動掛鉤不返回的內容,返回是過濾器鉤子。也許你修改header.php模板。這個問題很有趣!我也需要這個! –
我在所有需要它的模板(如index.php,single.php等等)中使用'get_header()',而沒有任何修改。 – superwinner