WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] admin_head-(plugin_page) with custom post type

[Resolved] admin_head-(plugin_page) with custom post type

  • Hello!

    I’m trying to insert some content in <head> on a custom post type admin page (named short-facts).

    It works using the admin_head hook. But I want to target the specific page using admin_head-(plugin_page). Like this:

    function some_css(){
    echo '<style type="text/css">...</style>';
    }
    add_action('admin_head-short-facts', 'some_css');

    Can’t get it to work though. The example on http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head-%28plugin_page%29 is using the add_options_page function for doing this. Here I’m just having a regular register_post_type which means that I don’t have to add any pages “manually”.

    Is it possible to solve? Should I do this with some kind of filter instead?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Assuming you want to target the page that lists the posts for that type, i’d suggest the following..

    add_action( 'admin_head-edit.php', 'yourfunction' );
    function yourfunction() {
    
    	// Bring the post type global into scope
    	global $post_type;
    
    	// If the current post type doesn't match, return, ie. end execution here
    	if( 'your-post-type-name-here' != $post_type )
    		return;
    
    	// Else we reach this point and do whatever
    	?>
    	<style type="text/css"></style>
    	<?php
    }

    Or similarly if you want to cover every page for that post type, you can do it this way..

    add_action( 'admin_head', 'yourfunction' );
    function yourfunction() {
    
    	// Bring the post type global into scope
    	global $post_type;
    
    	// If the current post type doesn't match, return, ie. end execution here
    	if( 'your-post-type-name-here' != $post_type )
    		return;
    
    	// Else we reach this point and do whatever
    	?>
    	<style type="text/css"></style>
    	<?php
    }

    Which then covers the post listing and the create new / edit pages to.

    Thank you Mark! It’s perfect!
    And thanks for a really quick response, I really appreciate it.

    You’re most welcome.. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] admin_head-(plugin_page) with custom post type’ is closed to new replies.