我想把JavaScript代碼放在前端的某些頁面上,但輸出結果是空的。
add_action( 'wp_footer', function ( ) {
$screen = get_current_screen();
var_dump( $screen ) 。
}, 999 )。)
uj5u.com熱心網友回復:
它將 "回傳當前的螢屏物件或當螢屏未定義時回傳空"。
如果你想用它來檢測admin頁面,那么就使用一個不同的鉤子,例如你可以使用current_screen鉤子:
add_action('current_screen', ' detecting_current_screen') 。
function detecting_current_screen()
{
$current_screen = get_current_screen();
print_r($current_screen) 。
}
或者
add_action('current_screen', ' detecting_current_screen') 。
function detecting_current_screen()
{
global $current_screen;
print_r($current_screen)。
如果你想在client-side上使用它并且回傳null,那么你可以使用一個名為$pagenow的全域變數。
注意: $pagenow將給你提供模板的名稱。
global $pagenow;
echo $pagenow;
或者
echo $GLOBALS["pagenow"/span>] 。
這應該會給出你所處的模板名稱:
這應該會給出你所處的模板名稱。
add_action( 'wp_footer', function ( ) {
global $pagenow;
echo $pagenow;
}, 999 )。)
如果上面提到的方法都不適合你,那么你可以使用另一個名為$post的全域變數。
或者
你可以通過使用:
來檢查你的頁面。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/307829.html
標籤:
