3

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.

9
  • css-tricks.com/snippets/wordpress/… Commented Aug 31, 2013 at 23:01
  • stackoverflow.com/questions/3326967/… Commented Aug 31, 2013 at 23:02
  • 5
    This question appears to be off-topic because it is about a support request for tailoring wordpress. It is explained not only in the product documentation of wordpress, there is also a Q&A site dedicated to Wordpress alone. Commented Aug 31, 2013 at 23:07
  • It doesn't work. tried that also, but it works with scripts on functions.php page, so if i have small custom portion of javascript i should include it with admin_head but not if script is in separated js file, that i should first register, than enqueue as i understood. Commented Aug 31, 2013 at 23:11
  • @AleksandarĐorđević you're right, i see only registration function i don't see enqueue. Try adding wp_enqueue_script( 'jquery-ui-core' ); and wp_enqueue_script( 'jquery-ui-tabs' ); functions inside the script hook. It could Help you to get these things to work. Commented Aug 31, 2013 at 23:19

1 Answer 1

1

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' );
Sign up to request clarification or add additional context in comments.

6 Comments

The hook is used only in case if you target specific page, you can use it without a hook also but it will load on all pages, i have read the codex, so per codex if in function i use wp_enqueue_scripts('jquery-ui') and than activate it with add_action('admin_enqueue_scripts', 'my_enqueue') this should work, but it doesn't
What is the console saying? Anything specific and which JS files get loaded?
It doesn't say anything wrong, i don't get any js errors, wordpress is fresh install and i don't have any other code in my theme except this what i try to include, it's just like the action hook is not even there in functions.php file.
Hmm please keep me posted, I'm stumped!
Spending so many hours in debugging something for what no one can get explanation when simple 5 minute re-installation can fix it is so frustrating. It looks like something was wrong with my installation of wordpress, either it wasn't completed right, or some file was missing or wasn't completed during copying wordpress on server. I just reinstalled wordpress with fresh install, and copied theme files with what i did so far and it worked.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.