public
Last active

Remove the "standard" WordPress post format.

  • Download Gist
no-standard-pf.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
/*
Plugin Name: No Standard Post
Description: Removes the standard post format.
Author: Christopher Davis
Author URI: http://christopherdavis.me
*/
 
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'
);
}
 
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;
}
 
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;
}

sorry dear this is not good solution

make this by add_theme_support

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.