I've built a basic meta box and have this in my functions.php.

The current code:

add_action( 'admin_print_styles-post-new.php', 'portfolio_admin_style', 11 );
add_action( 'admin_print_styles-post.php', 'portfolio_admin_style', 11 );

function portfolio_admin_style() {
    global $post_type;
    if( 'portfolio' == $post_type )
        wp_enqueue_style( 'portfolio-admin-style', get_stylesheet_directory_uri() . '/styles/portfolio-admin.css' );

add_action('init', 'create_portfolio');
    function create_portfolio() {
        $portfolio_args = array(
            'label' => __('Portfolio'),
            'singular_label' => __('Portfolio'),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'rewrite' => true,
            'supports' => array('title', 'editor', 'thumbnail')

// Input fields
add_action("admin_init", "add_portfolio");
    add_action('save_post', 'update_website_url');
    function add_portfolio(){
        add_meta_box("portfolio_details", "Portfolio Options", "portfolio_options", "portfolio", "normal", "low");
    function portfolio_options(){
        global $post;
        $custom = get_post_custom($post->ID);
        $website_url = $custom["website_url"][0];
        $port_excerpt = $custom["port_excerpt"][0];

    <div id="portfolio-options">
        <label>Website URL:</label><input name="website_url" value="<?php echo $website_url; ?>" />
        <label>Excerpt:</label><input name="port_excerpt" value="<?php echo $port_excerpt; ?>" />       
    </div><!--end portfolio-options-->   
    function update_website_url(){
        global $post;
        update_post_meta($post->ID, "website_url", $_POST["website_url"]);
        update_post_meta($post->ID, "port_excerpt", $_POST["port_excerpt"]);

add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
add_action("manage_posts_custom_column",  "portfolio_columns_display");

function portfolio_edit_columns($portfolio_columns){
    $portfolio_columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Project Title",
        "description" => "Description",
    return $portfolio_columns;

function portfolio_columns_display($portfolio_columns){
    switch ($portfolio_columns)
        case "description":

The problem is the stylesheet isn't changing the custom meta box's styling! I have the stylesheet being called from the correct directory in the code. If it matters, this is being used with custom post templates.

4 Answers 4


Remove the wp_enqueue_style line from the above code and replace it with this:

add_action( 'admin_print_styles-post-new.php', 'portfolio_admin_style', 11 );
add_action( 'admin_print_styles-post.php', 'portfolio_admin_style', 11 );

function portfolio_admin_style() {
    global $post_type;
    if( 'portfolio' == $post_type )
        wp_enqueue_style( 'portfolio-admin-style', get_stylesheet_directory_uri() . '/css/portfolio-admin.css' );

It is better to put the styling for the admin panel in a separate file like in a theme_directory/css/portfolio-admin.css as the front-end styling could conflict with the admin styles.

  • I get this... Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback Nov 23, 2011 at 4:45
  • Are you sure it is with regard to the above code I suggested? Can I have a look at the code in your template? Nov 23, 2011 at 4:57
  • pastebin.com/Uyqe0070 Nov 23, 2011 at 5:26
  • Sorry. The called function name was wrong. I have updated the answer. Have a go at the revised answer. Nov 23, 2011 at 5:42
  • That fixed the error, but for whatever reason it isn't changing the style of the form at all :-S Nov 23, 2011 at 5:57

Use the admin_enqueue_scripts or admin_print_styles action hooks and wp_enqueue_style like you would on the front end.

  • Could you be more specific as to how I'd do this? I'm having no luck. Having no luck with: wp_enqueue_style('my_meta_css', MY_THEME_PATH . '/style.css');.. I'll post my entire code above. Nov 20, 2011 at 21:40

First things first, I'm not sure there's a $post_type global but pretty sure there is a $post->post_type so you should probably be comparing to that. Secondly, unless you want your child themes to completely override all your CSS files (i.e. not use them even if not overriden) then you should be using get_template_directory_uri() instead of stylesheet directory.

Then, to make sure your stylesheet is included, view the source of the add new portfolio item page and see if your stylesheet is there and that the link is not broken, i.e. it links to the correct CSS file.

Finally, make sure the rules in your stylesheet are not the problem (as @ptriek mentioned above), add a #portfolio-options label { color: red !important; } and remove everything else from the stylesheet, this should turn your portfolio option labels to red. If it works then your stylesheet is fine and the rest is up to its contents :)

Good luck!


If this does not change the css style on your custom meta box, the problem is most likely with your css.

add_action('admin_enqueue_scripts', 'portfolio_admin_style');

function portfolio_admin_style($hook) {
    global $page_handle;
    if ( ($hook == 'post.php') || ($hook == 'post-new.php') || ($hook == 'page.php') || ($hook == 'page-new.php') || ($_GET['page'] == $page_handle) ) {
        wp_enqueue_style( 'portfolio-admin-style', (get_stylesheet_directory_uri() . '/css/portfolio-admin.css'), false, '1.0.0' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.