WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] admin_head-(plugin_page) with custom post type (4 posts)

  1. Erik
    Member
    Posted 2 years ago #

    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!

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    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.

  3. Erik
    Member
    Posted 2 years ago #

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

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    You're most welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic