• I was wondering if anyone knew how to include custom Javascript in the write panels for a custom post type. I’ve been able to get the custom post type working for the most part but need a little custom javascript magic for a few pieces. I’d like to be able to include it via a script tag in the header if at all possible.

    I’ve tried searching through the forums and haven’t been able to come up with anything.

    Thanks,
    Jon

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    As far as I can see their is no clean way in 3.0b1 of doing this, but I’m not really a plugin/wordpress expert nor do I develop much.. Probably a more experienced developer could come up with a cleaner solution, but untill then you could use this :

    Around the same line where you call the admin init hook you do
    add_action("admin_enqueue_scripts",array(&$this,"testaddjs"));

    (I’m assuming you’re using a plugin with class here)

    In your pluginclass you put the function

    function testaddjs($hook_suffix) {
    	global $typenow;
    	if ($typenow=="songtekst") {
    		echo "<script src='../wp-content/plugins/test.js' type='text/javascript'></script>";
    	}
    }

    where “songtekst” is your custom taxonomy’s slug. (for reference, hook_suffix is the page called, like post-new.php, and typenow is the post_type parameter in the url.

    Good luck!

    Edit : Interesting links :
    3.0b1 /wp-admin/admin.php in svn
    admin_enqueue_scripts as a 2.9 hook
    add_action in the Codex Function Reference

    Thanks so much for sharing this solution Wimsito.

    I have been trying to do something similar, add CSS to the admin pages for just the a custom post type, and the code worked perfectly for that.

    It is surprisingly easy to create a custom post type with a plugin, but tough to add a settings menu, icons, and other things to really customize that new post type.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘3.0b1 custom post types and javascript’ is closed to new replies.