Skip to content

Instantly share code, notes, and snippets.

@man4toman
Created October 4, 2018 11:38
Show Gist options
  • Save man4toman/bb090fd2ba5b78cfc4798cc8b4d92dcc to your computer and use it in GitHub Desktop.
Save man4toman/bb090fd2ba5b78cfc4798cc8b4d92dcc to your computer and use it in GitHub Desktop.
Add tinymce editor for post excerpt
<?php
add_action( 'add_meta_boxes', array ( 'add_tinymce_to_excerpt', 'switch_boxes' ) );
class add_tinymce_to_excerpt{
public static function switch_boxes(){
if ( ! post_type_supports( $GLOBALS['post']->post_type, 'excerpt' ) ){
return;
}
remove_meta_box( 'postexcerpt', '', 'normal' );
add_meta_box( 'postexcerpt2', 'Excerpt' , array ( __CLASS__, 'show' ), null, 'normal', 'core' );
}
public static function show( $post ){
?>
<label class="screen-reader-text" for="excerpt">Excerpt</label>
<?php
wp_editor( self::unescape( $post->post_excerpt ), 'excerpt', array ( 'textarea_rows' => 15, 'media_buttons' => false, 'teeny' => false, 'tinymce' => true ) );
}
public static function unescape( $str ){
return str_replace( array ( '&lt;', '&gt;', '&quot;', '&amp;', '&nbsp;', '&amp;nbsp;' ), array ( '<', '>', '"', '&', ' ', ' ' ), $str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment