Here’s some neat code that will enable the TinyMCE rich text editor within your excerpts box. You can now insert links and other HTML into your excerpts.
This code should be inserted into your theme’s functions.php, or better still create a plugin out of it.
function tinymce_excerpt_js(){
<script type="text/javascript">
jQuery(document).ready( tinymce_excerpt );
function tinymce_excerpt() {
jQuery("#excerpt").addClass("mceEditor");
tinyMCE.execCommand("mceAddControl", false, "excerpt");
tinyMCE.onAddEditor.add(function(mgr,ed) {
if(ed.id=="excerpt"){
ed.settings.theme_advanced_buttons2 ="";
ed.settings.theme_advanced_buttons1 = "bold,italic,underline,seperator,justifyleft,justifycenter,justifyright,separator,link,unlink,seperator,pastetext,pasteword,removeformat,seperator,undo,redo,seperator,spellchecker,";
}
});
}
</script>
add_action( 'admin_head-post.php', 'tinymce_excerpt_js');
add_action( 'admin_head-post-new.php', 'tinymce_excerpt_js');
function tinymce_css(){ ?>
<style type='text/css'>
#postexcerpt .inside{margin:0;padding:0;background:#fff;}
#postexcerpt .inside p{padding:0px 0px 5px 10px;}
#postexcerpt #excerpteditorcontainer { border-style: solid; padding: 0; }
</style>
add_action( 'admin_head-post.php', 'tinymce_css');
add_action( 'admin_head-post-new.php', 'tinymce_css');
function prepareExcerptForEdit($e){
return nl2br($e);
}
add_action( 'excerpt_edit_pre','prepareExcerptForEdit');
To take it a step further, check out how to add buttons to the TinyMCE editor.
One Response
Is there a way to DISABLE TinyMCE (Advanced) for WooCommerce Shoprt Description (like excerpt field) ?