Skip to content

Instantly share code, notes, and snippets.

@paaljoachim
Last active February 13, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paaljoachim/64c5a1f905d53a526828 to your computer and use it in GitHub Desktop.
Save paaljoachim/64c5a1f905d53a526828 to your computer and use it in GitHub Desktop.
TinyMCE Excerpt snippet. An easier way to show a more stylized excerpt.
/************************** https://github.com/cosmic/cosmic-tinymce-excerpt
* Plugin Name: Cosmic TinyMCE Excerpt
* Description: TinyMCE pour les extraits
* Author: Agence Cosmic
* Author URI: http://agencecosmic.com/
* Version: 1.0
****************************/
function cosmic_activate_page_excerpt() {
add_post_type_support('page', array('excerpt'));
}
add_action('init', 'cosmic_activate_page_excerpt');
# Removes default extracts and replaces them with new blocks
function cosmic_replace_post_excerpt() {
foreach (array("post", "page") as $type) {
remove_meta_box('postexcerpt', $type, 'normal');
add_meta_box('postexcerpt', __('Excerpt'), 'cosmic_create_excerpt_box', $type, 'normal');
}
}
add_action('admin_init', 'cosmic_replace_post_excerpt');
function cosmic_create_excerpt_box() {
global $post;
$id = 'excerpt';
$excerpt = cosmic_get_excerpt($post->ID);
wp_editor($excerpt, $id);
}
function cosmic_get_excerpt($id) {
global $wpdb;
$row = $wpdb->get_row("SELECT post_excerpt FROM $wpdb->posts WHERE id = $id");
return $row->post_excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment