dongluanjie8678 2013-08-31 23:01
浏览 108

如何将自定义css和js文件添加到wordpress的管理区域[关闭]

The question is asked too many times and there are too many different questions and for some reason it seems that i can't get it to work with none of the answers i have found. The very strange thing is that i had developed themes earlier and it was working.

I need to make some options to my theme, so i made separated menu in wordpress admin area and it works, i added some options to that page and it's shown, also saving options works.

Now i wanted to make a bit more options and make them tabbed with jquery ui tabs. I know that wordpress natively supports jquery ui now but it needs to be called additionally to load.

So after messing too many with code i at the end ended pulling a code from generatewp.com site which should work, but it don't, why i can't understand that.

The current code now is:

function custom_styles() {

wp_register_style( 'jquery-ui-style', 'http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', false, false );

}

// Hook into the 'admin_enqueue_scripts' action
add_action( 'admin_enqueue_scripts', 'custom_styles' );


// Register Script
function custom_scripts() {

wp_register_script( 'jquery-ui-core', '', array( 'jquery' ), false, false );

wp_register_script( 'jquery-ui-tabs', '', array( 'jquery' ), false, false );

}

// Hook into the 'admin_enqueue_scripts' action
add_action( 'admin_enqueue_scripts', 'custom_scripts' );

According to wordpress records this should register jquery ui tabs and style but it doesn't.

I tried many other combinations and it simply doesn't work. Why i can't understand that.

  • 写回答

1条回答 默认 最新

  • dou12754 2013-08-31 23:42
    关注

    Straight from the codex @admin_enqueue_scripts There are specific hooks to do what you're trying to do.

    function my_enqueue($hook) {
        if( 'edit.php' != $hook )
            return;
        wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
    }
    add_action( 'admin_enqueue_scripts', 'my_enqueue' );
    
    
    function load_custom_wp_admin_style() {
            wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
            wp_enqueue_style( 'custom_wp_admin_css' );
    }
    add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题