我正试图整理一些已经运行了很长时间的代码。具体来说,我过去常常在header.php
我正试图将其转变为functions.php
.
应仅为中具有特定值的页面加载其中一个脚本wp_postmeta
. 准确地说,当且仅当此表具有true
对于meta_key "mathjax"
, 应加载mathjax脚本。
在里面header.php
我用过
function my_init() {
if (!is_admin()) {
// REGISTER/ENQUEUE OTHER SCRIPTS...
$mathjax = get_post_meta($post->ID,\'mathjax\',true);
if($mathjax == \'y\'){
wp_enqueue_script(\'mathjax\');
}
}
}
add_action(\'init\', \'my_init\');
现在,此代码在中不起作用functions.php
因为$post
未定义。我还能把代码移到functions.php
如果是这样的话,我怎样才能让它工作呢?