Vous cherchez un moyen d’ajouter un bouton <hr />
à l’éditeur ? Bien qu’il existe probablement un plugin pour cela, nous avons créé un extrait de code rapide que vous pouvez utiliser pour ajouter un bouton de règle horizontale à l’éditeur dans WordPress.
Instructions:
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 enable_more_buttons($buttons) { $buttons[] = 'hr'; return $buttons; } add_filter("mce_buttons", "enable_more_buttons");
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 : 9 meilleurs plugins WordPress pour l’immobilier et comment configurer le suivi Google Analytics eCommerce pour WooCommerce.
Brilliant! Been looking for this for a while!
thanks!
thank you for the quick code..
Hey thanks for the quick code, it appeared near first on Google for my search result and was exactly what I needed. I’m still kinda amazed WordPress even in version 3 doesn’t have the HR element as a button in TinyMCE.. Weird.
Thanks again!
color me dumb, but add the snippet WHERE in the functions.php file (which, by my count is four thousand five hundred and fifty-four lines long)?
I put this snippet at the very bottom of the functions.php file and got a fatal error crash…any ideas?
Hi Ken,
I posted the code sample http://pastebin.com/nkk6bZ8B
Keep in mind if you have any line breaks after the last ? > it will cause an error make sure no space after the last ? >. however the location does not matter. If you continue to get errors post the code into pastebin.com and ill check things out if you still have problems.
thanks- I really do appreciate your efforts and the reply but its just not working for my theme, and I still know how to type an “h” and an “r” hehehehehehe.
Thanks anyway, maybe someday WordPress will include this feature in an update….
This is not so much a wordpress option as a TinyMCE option, if you wanted to post your functions.php file within the pastebin.com website I can take a look and fix the problem for you. Just paste the code and reply with the URL and ill check things out. If you don’t want to post publicly you can use the wpsnipp contact form.
http://wpsnipp.com/contact/
Hi Ken,
It does not appear that this is the whole file however if it is I fixed the problem.
http://pastebin.com/dzK56W4v
Great! Thanks for sharing.
np glad you like the snippet.
[…] has provided a little snippet of code that will add a “horizontal rule” (or <hr />) button to the default editor in […]
Useful!
yes the other things you could do is create a few shortcodes to drop in html elements you need. Check out this snippet.
http://wpsnipp.com/index.php/functions-php/add-custom-media_buttons-for-shortcode-selection/
Excellent!
thanks pippin