Activer l’éditeur TinyMCE pour le post the_excerpt

Snippets by IsItWP

Voulez-vous ajouter l’éditeur TinyMCE à la zone de texte de l’extrait de l’article ? Bien qu’il y ait probablement un plugin pour cela, nous avons créé un extrait de code rapide que vous pouvez utiliser pour activer l’éditeur TinyMCE pour le post the_excerpt WordPress.


Tout ce que vous avez à faire est d’ajouter ce code au fichier functions.php de votre thème ou dans un plugin spécifique à votre site:

function tinymce_excerpt_js(){ ?>
<script type="text/javascript">
	jQuery(document).ready( tinymce_excerpt ); 
            function tinymce_excerpt() {
		tinyMCE.execCommand("mceAddControl", false, "excerpt");
<?php }
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; }	
<?php }
add_action( 'admin_head-post.php', 'tinymce_css');
add_action( 'admin_head-post-new.php', 'tinymce_css');

Note : Si c’est la première fois que vous ajoutez des extraits de code dans WordPress, veuillez consulter notre guide sur la façon d’ajouter correctement des extraits de code dans WordPress, afin de ne pas casser accidentellement votre site.

Si vous avez aimé cet extrait de code, n’hésitez pas à consulter nos autres articles sur le site comme : 7 meilleurs services VPN pour les utilisateurs de WordPress et comment créer un formulaire de demande d’emploi sur WordPress.

Commentaires   laisser une réponse

  1. This doesnt work in WP 5.5.1
    Is there something we need to update?
    Thank you!

  2. sen ne d?yorsun bree orospuu cocugu

  3. Adam Christianson août 11, 2014 à 1:33 pm

    I’m experiencing the same issue since updating. Is there an updated version of this function that might fix things up again?

  4. Same problem here! Was working before update but now it’s gone! Thanks!

  5. It was working before however after updating the tinyMCE its gone ???

  6. Appreciate the code and just added to local WP site I am updating and seemed to work great so far. Thank You!

    1. Perfect! Glad wpsnipp could help… Enjoy the code.

  7. Life saver! Thank you so much 🙂

  8. it EATS the line breaks…

  9. hi kevin,
    i added this snippet to my functions.php file but the editor doesn’t show. i’m using the pagelines framework. could it be because of that?

  10. thx! handy without installing a giant plugin. Only one little issue: when you have a custom post type without any editors, the tinyMCE init runs anyway causing all js to break. with an extra check it works smoothly:

    if (typeof(tinyMCE) !== ‘undefined’) {
    tinyMCE.execCommand(“mceAddControl”, false, “excerpt”);

  11. thx ! helped me a lot !

    1. Cool glad that I could help enjoy!

  12. any update on this? (this is mroncetwice btw)

  13. thanks! exactly what I was looking for 🙂

    1. Cool glad I could help Birgit,

  14. WP 3.3  messes this function up royally .. when you leave a write page set to the HTML tab, upon returning to any of the write pages where this function is active, clicking back to the Visual tab brings up a blank textarea (not actually blank, but appears so as text is colored white). i see a lot of suggestions to use 
    instead, but im not sure how do go about such a function. 

    any plans to update this function for use with WP 3.3?

    1. I have not tried this snippet in wp 3.3 could be a number of things ill take a look and post an updated version for 3.3 and let you know what if any issues may have caused this for you.

  15. 29 Wordpress Tweaks to Improve Posts and Pages octobre 18, 2011 à 9:11 am

    […] [Source: WPSNIPP] […]

  16. Is there any way to display tabs for switching between Visual and HTLM?

    1. Hi Jacek, a few people have requested this addition, ill have to look into it and see.

  17. Thanks Kevin for this snippet.
    Do you know how add the media buttons to the top ?
    Sorry for my bad English

    1. No problem Anne, glad that you like the snippet. In regards to media_buttons, ill have to check that out not sure if this can be done easily. If so ill post a snippet.

  18. Brokenflipside août 22, 2011 à 4:11 am

    How would I add this to the Additional Description field of WPEC ?

    1. To add this to another field you would need to the ID of the field. On row 05 you can see #excerpt if you change that to the ID of the other textarea should work great. Please also note that I added some CSS on lines 14-16  to style things a little. You should remove that css and replace it with your own to make sure everything looks ok.

      1. Brokenflipside août 22, 2011 à 3:46 pm

        Brilliant! So for any other WPEC/WPSC (wp E-commerce) folks out there want to get this to work for the “Additional Description” section, then just change the ID #excerpt in the above function to #additional_description and change the class that is being added from “mceEditor” to “theEditor” and all will work!

        Thanks Kevin for the great help.

      2. Brokenflipside août 22, 2011 à 7:13 pm

        Kevin, any idea how to add the visual/HTML tabs to the top of the excerpt?

        1. To be honest I’m not sure, this not something I have ever thought about doing until you asked the question however, it is an interesting idea. ll take a look into this and see if I can come up with a snippet that I can post.

  19. This is great — except, my line break/paragraphs aren’t preserved.  So after an update the excerpt appears as one long line again.  Is there an easy way to preserve paragraph breaks?

    1. Hi Gary ill test that out and get back to you,

      1. Hi Gary,
        I looked things over again and it should be working it breaks line breaks into paragraphs so it should be working fine. Do you have any other code that is doing something to the_excerpt ?

    2. I second that experience. But when viewing the content the paragraphs are there.

      I am more interested in learning how to include images. If you have the time, drop me a line at [email protected] with a solution.

Ajouter un commentaire

Nous sommes heureux que vous ayez choisi de laisser un commentaire. N'oubliez pas que tous les commentaires sont modérés conformément à notre privacy policy, et que tous les liens sont en nofollow. N'utilisez PAS de mots-clés dans le champ du nom. Engageons une conversation personnelle et constructive.

WordPress Launch Checklist

L'ultime liste de contrôle pour le lancement de WordPress

Nous avons rassemblé tous les éléments essentiels de la liste de contrôle pour le lancement de votre prochain site Web WordPress dans un ebook pratique.
Oui, envoyez-moi le gratuit !