Skip to content

Instantly share code, notes, and snippets.

@manishsongirkar
Created October 9, 2015 07:41
Show Gist options
  • Save manishsongirkar/de55c8a3f035e2cfcded to your computer and use it in GitHub Desktop.
Save manishsongirkar/de55c8a3f035e2cfcded to your computer and use it in GitHub Desktop.
Custom Post Format
<?php
/**
* Rename Aside post format to Look post format
*/
function rtp_rename_post_formats( $safe_text ) {
if ( $safe_text == __( 'Aside' , 'fab' ) ) {
return __( 'Look' , 'fab' );
}
return $safe_text;
}
add_filter( 'esc_html', 'rtp_rename_post_formats' );
/**
* Rename Aside in posts list table
*/
function rtp_live_rename_formats() {
global $current_screen;
if ( $current_screen->id == 'edit-post' ) { ?>
<script type="text/javascript">
jQuery( 'document' ).ready(function() {
jQuery( 'span.post-state-format' ).each( function() {
if ( jQuery(this).text() == <?php _e( 'Aside' , 'fab' ); ?> )
jQuery(this).text( <?php _e( 'Look' , 'fab' ); ?> );
} );
} );
</script>
<?php
}
}
add_action( 'admin_head', 'rtp_live_rename_formats' );
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function fab_look_body_classes( $classes ) {
foreach ( $classes as $key => $value ) {
if ( $value == 'single-format-aside' ) {
unset( $classes[ $key ] );
$classes[] = 'single-format-look';
}
}
return $classes;
}
add_filter( 'body_class', 'fab_look_body_classes' );
/**
* Update aside class to look class of post classes.
*
* @param array $classes Classes for the post element.
* @return array
*/
function fab_post_classes( $classes ) {
foreach ( $classes as $key => $value ) {
if ( $value == 'format-aside' ) {
unset( $classes[ $key ] );
$classes[] = 'format-look';
}
if ( $value == 'post_format-post-format-aside' ) {
unset( $classes[ $key ] );
$classes[] = 'post_format-post-format-look';
}
}
return $classes;
}
add_filter( 'post_class', 'fab_post_classes' );
/**
* Remove post format support for post type post
*/
function rtp_remove_support() {
remove_post_type_support( 'post', 'post-formats' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment