CI_*_*Guy 8 wordpress wordpress-plugin
不确定我是否正确措辞但基本上我想在仅使用实际插件的页面上加载插件CSS/JS ..我已经通过插件文件中wp_enqueue_script的插件中使用的任何句柄搜索完成了很多操作.只是wp_dequeue_script在functions.php中
但是,有一些样式的队列包括.php而不是css文件,例如..在插件中它将队列文件排队
wp_enqueue_style("myrp-stuff", MYRP_PLUGIN_URL . "/myrp-hotlink-css.php");
Run Code Online (Sandbox Code Playgroud)
所以我试过了:
wp_dequeue_style('myrp-stuff');
wp_deregister_style('myrp-stuff');
Run Code Online (Sandbox Code Playgroud)
它不起作用
但是,当页面/帖子呈现时,它显示为
<link rel='stylesheet' id='myrp-stuff-css' href='http://www.modernlogic.co/wp/wp-content/plugins/MyRP/myrp-hotlink-css.php?ver=3.4.2' type='text/css' media='all' />
Run Code Online (Sandbox Code Playgroud)
它将-css添加到id并拒绝出列/取消注册并移动.
我也试过以下没有运气
wp_dequeue_style('myrp-stuff-css');
wp_deregister_style('myrp-stuff-css');
Run Code Online (Sandbox Code Playgroud)
有什么建议?
lee*_*ers 14
脚本和样式可以在wp_print_*触发操作之前的任何顺序和任何时间排队.这可能使得在输出之前很难将它们从队列中删除.
使出列工作始终挂入wp_print_styles或wp_print_scripts具有高优先级,因为这将在输出之前删除脚本和样式.
例如,在您的插件加载器代码或模板的functions.php文件中,您可以使用如下函数和操作挂钩:
function remove_assets() {
wp_dequeue_style('myrp-stuff');
wp_deregister_style('myrp-stuff');
}
add_action( 'wp_print_styles', 'remove_assets', PHP_INT_MAX );
Run Code Online (Sandbox Code Playgroud)
设置高priority(第三个参数add_action)时钩住行动将有助于确保回调remove_assets被称为最后,打印脚本/风格之前.
请注意,虽然此技术对于删除脚本/样式是合法的,但它不应用于添加资源.有关详细信息,请参阅此Wordpress Core博客文章.
只是为了确定,您是否已将代码放在由此类操作调用的函数中?:
add_action('wp_enqueue_scripts', 'dequeue_function');
function dequeue_function() {
wp_dequeue_style( array('myrp-stuff', 'myrp-stuff-css') );
wp_deregister_style( array('myrp-stuff', 'myrp-stuff-css') );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6367 次 |
| 最近记录: |