我正在尝试挂起customizer_preview_init操作,以触发我正在自定义程序中所做的更改的实时预览。然而,我的第一次考试失败了。我只是想在.js内部得到一个开火警报
知道我做错什么了吗?
//Add customizer.php to admin:
if ( is_admin() ) :
require_once( GENESIS_ADMIN_DIR . '/customizer.php' );customizer.php:
function mytheme_customizer_live_preview()
{
wp_enqueue_script(
'mytheme-themecustomizer', //Give the script an ID
get_template_directory_uri().'/framework/admin/customizer.js',//Point to file
array( 'customize-preview' ), //Define dependencies
'', //Define a version (optional)
true //Put script in footer?
);
}
add_action( 'customize_preview_init', 'mytheme_customizer_live_preview' );customizer.js
alert('customizer.js loaded!');
( function( $ ) {
alert('Customizer!');
//Do Stuff
} )( jQuery );更新:看来我的队列失败了。在dev tools资源面板中找不到customizer.js文件。
我已经验证了footer.php实际上确实有一个wp_footer()调用,就像预期的那样。这是创世纪的主题,也许是一些影响队列的过滤器?
发布于 2014-03-20 18:03:25
本例中的问题与我如何添加customize.php脚本有关。我将其加载到is_admin()检查中(请参阅上面更新的问题,其中包括了代码分支)。
在阅读了奥托职位之后,我意识到自定义程序钩子不会在这个上下文中触发。
https://wordpress.stackexchange.com/questions/138550
复制相似问题