Is it possible to remove the “standard” post format?

I’m using post formats heavily on a project, but have no current need for the standard option. Beyond being an unnecessary bit of UI, it actually causes broken behavior if it does get mistakenly selected. I might, with some convoluted logic, be able to set up a template for Standard that properly handles the incoming content of other formats, but all that would really do is hide the fact the posts are assigned incorrectly, making them even harder to hunt down. (And this workaround may or may not always be viable.) The real problem is that the radio button just shouldn’t be there.

The only option I’ve seen for removing format support in any way is remove_theme_support('post-formats') which kills the feature altogether. I just want that one option gone.

Related posts

Leave a Reply

4 comments

  1. The first thing to remember about the post editing screen is that everything (except for the post title, editors, permalink, etc.) is a meta box. Since you can easily add and remove meta boxes, there’s no need for CSS and JS hacking. Don’t want the standard post format to show up? Remove the default meta box and roll your own.

    First hook into add_meta_boxes_{$post_type} and remove the old format div, and add your own.

    <?php
    add_action( 'add_meta_boxes_post', 'wpse41940_meta_boxes' );
    function wpse41940_meta_boxes( $post )
    {
        remove_meta_box(
            'formatdiv',
            $post->post_type,
            'side'
        );
        add_meta_box( 
            'wpse41940_formatdiv', 
            _x( 'Format', 'post format' ), 
            'wpse41940_format_meta_box', 
            $post->post_type, 
            'side', 
            'core' 
        );
    }
    

    You can find the code for the default post format meta box in wp-admin/includes/meta-boxes.php inside the function post_format_meta_box. Here it is:

    <?php
    function post_format_meta_box( $post, $box ) {
        if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) :
        $post_formats = get_theme_support( 'post-formats' );
    
        if ( is_array( $post_formats[0] ) ) :
            $post_format = get_post_format( $post->ID );
            if ( !$post_format )
                $post_format = '0';
            // Add in the current one if it isn't there yet, in case the current theme doesn't support it
            if ( $post_format && !in_array( $post_format, $post_formats[0] ) )
                $post_formats[0][] = $post_format;
        ?>
        <div id="post-formats-select">
            <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0"><?php _e('Standard'); ?></label>
            <?php foreach ( $post_formats[0] as $format ) : ?>
            <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label>
            <?php endforeach; ?><br />
        </div>
        <?php endif; endif;
    }
    

    The easiest thing to do is to copy the entire deal, rename the function and change the stuff we need to change. Name, that means changing this:

    $post_format = get_post_format( $post->ID );
    if ( !$post_format )
        $post_format = '0';
    

    To the following to set the “default format” to aside (or whatever you want it to be).

    $post_format = get_post_format( $post->ID );
    if ( !$post_format )
        $post_format = 'aside';
    

    We’ll also need to remove this line:

    <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0"><?php _e('Standard'); ?></label>
    

    Which is the “standard” post format. The final result:

    <?php
    function wpse41940_format_meta_box( $post, $box )
    {
        if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) :
        $post_formats = get_theme_support( 'post-formats' );
    
        if ( is_array( $post_formats[0] ) ) :
            $post_format = get_post_format( $post->ID );
            if ( !$post_format )
                $post_format = 'aside';
            if ( $post_format && !in_array( $post_format, $post_formats[0] ) )
                $post_formats[0][] = $post_format;
        ?>
        <div id="post-formats-select">
            <?php foreach ( $post_formats[0] as $format ) : ?>
            <input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label><br/>
            <?php endforeach; ?><br />
        </div>
        <?php endif; endif;
    }
    

    Finally, it would be a good idea to make sure get_post_format never returns false, or, rather, also returns your default format in the absence of a format. Post formats are just a taxonomy, so we can hook into get_the_terms and make sure we always have a post format. Formats are created as posts are added to them, so we have to add the taxonomy if it doens’t exist already.

    <?php
    add_filter( 'get_the_terms', 'wpse41940_filter_formats', 10, 3 );
    function wpse41940_filter_formats( $terms, $post_id, $taxonomy )
    {
        if( 'post_format' != $taxonomy ) return $terms;
        if( empty( $terms ) )
        {
            $aside = get_term_by( 'slug', 'post-format-aside', 'post_format' );
            // post formats are created as posts are saved in them.
            // so this is a bit of a hack
            if( $aside )
            {
                $terms[] = $aside;
            }
            else
            {
                $term = wp_insert_term( 'post-format-aside', 'post_format' );
                $terms[] = get_term( $term['term_id'], 'post_format' );
            }
        }
        return $terms;
    }
    

    Here is all that as a plugin.

  2. Based on your comment:

    Because if something ends up in that format, the templating will come out wrong(to varying degree depending how customized the other formats are), and there’s no good way to determine that without visiting every single post and just knowing it’s supposed to be in some other format. There’s also no reason to template standard at all(in my case, it will never be used; yes, really). If I did it may still not be possible for the fallback to look okay, and as I said it would just make the discovery problem above even worse because now the things in standard won’t look as obviously wrong.

    I think the most correct approach is for you not to use the Post Format taxonomy at all; rather, you should be using your own custom taxonomy. You’re not using the Post Format taxonomy as it is intended to be used, and it doesn’t serve your purposes; so, why try to force a square peg into a round hole?

    Just register your own taxonomy (heck, even copy the useful bits from the post format taxonomy registration code), and omit “standard” term/handling altogether.

  3. This is a semi-hacky workaround, but I think it meets all your needs. First, implement the template logic to handle the case where for some reason you do have a post that is set as the “Standard” post format.

    $format = get_post_format();
    if ( false === $format ) // post format is 'standard'
        $format = 'aside'; // set it instead to 'aside' (or whatever you want)
    <?php get_template_part( 'content', $format ); ?>
    

    Next, create a simple plugin that will add custom CSS and JS in your admin interface. Create a “myplugin” directory under /wp-content/plugins and place this code in “myplugin.php”:

    <?php
    /*
    Plugin Name: My Admin Theme
    Plugin URI: http://yoursite.com
    Description: My WordPress Admin Theme - Add Custom CSS and JS.
    Author: Your Name
    Version: 1.0
    */
    
    function my_admin_head() {
            echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('wp-admin.css', __FILE__). '">';
            echo '<script type="text/javascript" src="' .plugins_url('wp-admin.js', __FILE__). '"></script>';
    }
    
    add_action('admin_head', 'my_admin_head');
    ?>
    

    Next, also in the /myplugin/ folder, create the above referenced wp-admin.css and wp-admin.js files.

    In wp-admin.css put styles to remove the “Standard” option from being seen by your Authors:

    /* Custom styles to remove the Standard option from the view in the post page */
    #post-formats-select input:nth-child(1),
    #post-formats-select label:nth-child(2),
    #post-formats-select br:nth-child(3) {
        display:none;
    }
    

    Finally, in wp-admin.js place a line of JavaScript that will select the post format that you want the users to use by default.

    jQuery(document).ready(function() {
        jQuery('input:radio[name=post_format][value=aside]').click();
    });
    

    The caveat of this approach is that this isn’t actually removing the Standard post format in WP, but simply hiding it from your Authors using JavaScript and CSS. If the Author doesn’t have JS enabled in their browser, the “Standard” post will still be the default selected. I believe this is still the best and only solution to this issue though.

    Good luck!

  4. Ist not enough you add the post format and filter via the array of allowed post formats? maybe i dont understand the question not right.

    in functions.php of the Theme; allowed post format for Aside and Image.

    add_theme_support( 'post-formats', array( 'aside', 'image' ) );