Last active
October 1, 2019 20:36
-
-
Save carlodaniele/191a53574e3d7965c5e1a49965ec2678 to your computer and use it in GitHub Desktop.
This is an example of usage of the WordPress Quicktags API, quicktags_settings filter and wp_editor function. This is not a ready-to-use plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add scripts to admin page footer | |
* | |
* @since 2.8.0 | |
* | |
*/ | |
function my_quicktags() { | |
if ( wp_script_is( 'quicktags' ) ) { | |
?> | |
<script type="text/javascript"> | |
QTags.addButton( 'eg_php', 'PHP', '<pre><code class=\"language-php\">', '</code></pre>', 'p', 'PHP Code', 200 ); | |
QTags.addButton( 'eg_css', 'CSS', '<pre><code class=\"language-css\">', '</code></pre>', 'q', 'CSS Code', 201 ); | |
QTags.addButton( 'eg_html', 'HTML', '<pre><code class=\"language-html\">', '</code></pre>', 'r', 'HTML Code', 202 ); | |
QTags.addButton( 'eg_callback', 'CSS div', css_callback ); | |
function css_callback(){ | |
var css_class = prompt( 'Class name:', '' ); | |
if ( css_class && css_class !== '' ) { | |
QTags.insertContent('<div class="' + css_class +'"></div>'); | |
} | |
} | |
</script> | |
<?php | |
} | |
} | |
add_action( 'admin_print_footer_scripts', 'my_quicktags' ); | |
/** | |
* Filters the Quicktags settings. | |
* | |
* @since 3.3.0 | |
* | |
* @param array $qtInit Quicktags settings. | |
* @param string $editor_id The unique editor ID, e.g. 'content'. | |
*/ | |
function my_quicktags_2( $qtInit, $editor_id = 'content' ) { | |
$qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close'; | |
return $qtInit; | |
} | |
add_filter( 'quicktags_settings', 'my_quicktags_2', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment