[wp-hackers] Best way to detect post type in admin

Lox lox.dev at knc.nc
Thu Jul 15 03:55:15 UTC 2010


Hello,

In a plug-in I want to enqueue scripts only on a specific post type
new/edit form page.

What is the best way to achieve it ?

I ended up by doing this:

if(is_admin()) {
    if( isset($_GET['post_type']) ) $post_type = $_GET['post_type'];
    else if( isset($_GET['post']) && isset($_GET['action']) &&
$_GET['action'] === 'edit') $post_type = get_post_type($_GET['post']);

    if($post_type === 'posttype') {
       // enqueue scripts
    }
}

But it also includes script on the custom posts list page, witch I don't want.

Isn't it a "cleaner" way to do it ?

-- 
Lox
lox.dev at knc.nc


More information about the wp-hackers mailing list