WordPress.org

Ready to get started?Download WordPress

Forums

3.0b1 custom post types and javascript (3 posts)

  1. jonlb01
    Member
    Posted 4 years ago #

    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

  2. Wimsito
    Member
    Posted 4 years ago #

    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

  3. Josh Leuze
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic