Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
<?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
You can’t perform that action at this time.