Adding ICONS to CPT in wordpress

I have this function, it is supposed to handle icons for CPT in wordpress , but Somehow it is not working ..

   add_action('admin_head', 'fbdf_cpt_icons_add');
    function fbdf_cpt_icons_add() {

        ?>
        <style>
        <?php if (($_GET['post_type'] == 'my_cpt') || ($post_type == 'my_cpt')) : ?>
        #icon-edit { background:transparent url('<?php echo plugin_dir_url(__FILE__) .'/img/cpt.32.png';?>') no-repeat; }    
        <?php endif; ?>
            </style>
            <?php } 

Any ideas why ?

Related posts

Leave a Reply

1 comment

  1. yes, I have an idea..

    you need to make $post type global..

    Add global $post_type; to the beginning of your function like so ..

    add_action('admin_head', 'fbdf_cpt_icons_add');
        function fbdf_cpt_icons_add() {
          global $post_type; // here
            ?>
            <style>
            <?php if (($_GET['post_type'] == 'my_cpt') || ($post_type == 'my_cpt')) : ?>
            #icon-edit { background:transparent url('<?php echo plugin_dir_url(__FILE__) .'/img/cpt.32.png';?>') no-repeat; }    
            <?php endif; ?>
                </style>
                <?php }