我有一个主题名是mythemeinthemes/mythem/functions.php
I使用代码:
function remove_scripts() {
remove_action(\'wp_head\',\'mytheme_head_scripts\');
}
add_action(\'init\', \'remove_scripts\');
=>但result无法删除所有javascript,如何修复它?我有一个主题名是mythemeinthemes/mythem/functions.php
I使用代码:
function remove_scripts() {
remove_action(\'wp_head\',\'mytheme_head_scripts\');
}
add_action(\'init\', \'remove_scripts\');
=>但result无法删除所有javascript,如何修复它?您可以使用admin_*/wp_print_scripts
挂钩或admin_*/wp_print_styles
钩样式挂钩位于打印脚本挂钩之前,因此它可能比只使用优先级0
对于*_print_scripts
钩子(可能有一个函数的名称在优先级的前面被钩住了0
).
function wpse61635_remove_all_scripts()
{
global $wp_scripts;
$leave_alone = array(
// Put the scripts you don\'t want to remove in here.
);
foreach ( $wp_scripts->queue as $handle )
{
// Here we skip/leave-alone those, that we added above ↑
if ( in_array( $handle, $leave_alone ) )
continue;
$wp_scripts->remove( $handle );
}
}
add_action( \'wp_print_styles\', \'wpse61635_remove_all_scripts\', 0 );
如果功能mytheme_head_scripts
挂接时使用的优先级wp_head
那么您必须设置remove_action
具有相同的优先级。
Example -
function remove_scripts() {
remove_action(\'wp_head\',\'mytheme_head_scripts\',10);
}
add_action(\'init\', \'remove_scripts\');
我正在创建一个插件,插件目录中有一个php文件,可以通过自定义重写url直接访问该文件。我需要这个文件能够使用标题中提到的三个功能。目前,我正在包括wp负载。php文件,它使我能够访问所有这些函数。然而,我一直在读到不应该包括wp负载,因为它可能不总是在同一个位置,而且它包括可能不需要的wordpress文件。这就是我如何包含wp负载:$wp_base = explode($_SERVER[\'PHP_SELF\'], $_SERVER[\'SCRIPT_FILENAME\']); require