WP Mayor_Horizontal Logo
Search
Close this search box.

How to Enable TinyMCE for Post Excerpts Box

Here's some neat code that will enable TinyMCE 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.

Table of Contents

Sponsored Ad

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.

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

All suggestions are anonymous.

More from our blog...

One Response

Post a Comment

Your email address will not be published. Required fields are marked *

Stay updated with WP Mayor's newsletter showcase every week

Stay on top of every new WordPress innovation and latest launches. Receive all our fresh product reviews and expert guides directly in your inbox.

Hosting Survey 2024

Are you happy with your hosting provider or are you over-paying for too little? Have your say below!

"*" indicates required fields

What's the main reason you picked this host?*
How happy are you with your host?*

OPTIONAL: If you'd like to receive the results of this survey, please enter your details below.