WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
I get this... Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback – AndrettiMilas Nov 23 '11 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? – Joshua Abenazer Nov 23 '11 at 4:57
pastebin.com/Uyqe0070 – AndrettiMilas Nov 23 '11 at 5:26
Sorry. The called function name was wrong. I have updated the answer. Have a go at the revised answer. – Joshua Abenazer Nov 23 '11 at 5:42
That fixed the error, but for whatever reason it isn't changing the style of the form at all :-S – AndrettiMilas Nov 23 '11 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.

share|improve this answer
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. – AndrettiMilas Nov 20 '11 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!

share|improve this answer

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' );
share|improve this answer

I'm not sure if this is going to help, but:

  • Are you sure the problem isn't just CSS-related? Could you post the CSS-code?
  • Do the styles show up if you check the elements with Firebug?
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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