2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

I would like to enqueue scripts only if the editor is supported

This is what I have
function init(){
    global $post;
    if(!post_type_supports( $post->post_type, 'editor' )) return false;
    //enqueue scripts
}
add_action('admin_init', 'init');

Unfortunately $post is not defined yet. So I guess ‘admin_init’ is “to early” in the hook queue

147 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 250 000 and 1 000 000 dollars
FlexiPress says

this is my code


add_action( 'admin_menu', 'prima_editor_init' );
function prima_editor_init() {
    $post_types = get_post_types( array( 'show_ui' => true ), 'objects' );
    foreach ( $post_types as $type ) {
        if ( post_type_supports( $type->name, "editor" ) ) {
            add_action( "load-post.php", 'prima_editor_enqueue_script' );
            add_action( "load-post-new.php", 'prima_editor_enqueue_script' );
        }
    }
}

function prima_editor_enqueue_script() {
    // my wp_enqueue_script script
}
2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

Thanks, I’ll give it a try

by
by
by
by
by
by