doremifasodo0008008
2016-12-23 13:43
浏览 197
已采纳

在Wordpress中的某些管理页面上自定义css和JS

I created a plugin to export some specific content in Wordpress ( called cav and located in /wp-content/plugins/cav ) and I added its admin menu link in the Tools main menu as follows:

define( 'CAV_DIR', plugin_dir_path( __FILE__ ) );
define( 'CAV_URL', plugins_url()."/cav" );

function cavlfo_admin_enqueue($hook) {
global $post;
if ( $hook == 'post-new.php' || $hook=='tools.php?page=CAV' ) {

        wp_enqueue_style( 'cavlfo_style', CAV_URL. '/css/cav.css' );
  wp_enqueue_style(  'cavlfo_targetted', CAV_URL.'/css/targettedcss.css' );
        wp_enqueue_script(  'cavlfo_targetted', CAV_URL.'/js/targetted.js', array("jquery") );
}
}
add_action( 'admin_enqueue_scripts', 'cavlfo_admin_enqueue' );

All this works fine when I used

if( $hook == 'post-new.php' || $hook=='tools.php' ){ . . .}

but I want it to work ONLY when it's actually

if( $hook == 'post-new.php' || $hook=='tools.php?page=CAV' ){ . . .} (Only on the page is CAV )

Any suggestion?

图片转代码服务由CSDN问答提供 功能建议

我创建了一个插件,用于在Wordpress中导出一些特定内容(名为 cav </ strong>,位于 / wp-content / plugins / cav </ strong>)我在Tools主菜单中添加了管理菜单链接,如下所示:</ p>

  define('CAV_DIR'  ,plugin_dir_path(__ FILE __)); 
define('CAV_URL',plugins_url()。“/ cav”); 
 
function cavlfo_admin_enqueue($ hook){
global $ post; 
if($ hook =='post-new  .php'|| $ hook =='tools.php?page = CAV'){
 
 wp_enqueue_style('cavlfo_style',CAV_URL。'/ css / cav.css'); 
 wp_enqueue_style('cavlfo_targetted',  CAV_URL。'/ css / targettedcss.css'); 
 wp_enqueue_script('cavlfo_targetted',CAV_URL。'/ js / targetted.js',array(“jquery”)); 
} 
} 
add_action('admin_enqueue_scripts  ',''cavlfo_admin_enqueue'); 
 </ code> </ pre> 
 
 

当我使用</ p>

if($ hook = ='post-new.php'|| $ hook =='tools.php'){。 。 。} </ code> </ p>

但我希望它只在它实际上是</ p>

if($ hook =='post- new.php'|| $ hook =='tools.php?page = CAV'){。 。 。} </ code>(仅在页面上是CAV)</ p>

有任何建议吗? </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题