[英]What is wrong with this attempt using php to include functions.php and header.php file?
[英]Include php file in Wordpress' functions.php not working for header.php
我已經在我的functions.php
文件中包含了以下行(在頂部,在代碼底部也嘗試了該行)。 我可以在所有模板中訪問該文件中定義的變量和所有其他內容。 但是,當我嘗試從header.php中的該文件中echo $something
,什么都沒有顯示。 沒有內容,沒有錯誤消息。
require_once '/path/to/file.php';
好的,經過大量的嘗試,我發現在functions.php中使用上面的代碼
global $something;
echo $somtehing;
header.php中的內容顯示了wordpress標頭中的值。 模板文件中不需要global $something
。 能否請任何人解釋我為什么?
https://secure.php.net/manual/zh/reserved.variables.globals.php
謝謝!
我認為您可以創建一個簡碼並向header.php回顯簡碼https://codex.wordpress.org/Shortcode_API
例
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
並調用標題
<?php echo do_shortcode('[foobar]'); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.