Custom quicktags not working after Wordpress 6.0
wp 5.8.x/5.9.x: working -- wp 6.0: not working
Buttons are not showing here: https://i.stack.imgur.com/aUXyV.jpg
Console error: Uncaught ReferenceError: QTags is not defined
I am using this code.
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' );
QTags.addButton( 'eg_php', 'PHP', '<pre><code class=\"language-php\">', '</code></pre>', 'p', 'PHP Code', 200 );
in WP 6.0 and it worked fine, I notice though, that rather than adding an inline script toquicktags
, you're usingwp_script_is
and then manually writing out a script tag, which is highly unusual and non-standard. Are you sure thatif ( wp_script_is( 'quicktags' ) ) {
actually works as intended? Was there a particular reason you chose to write it this way? I suspect this has always been broken but it worked out of luck