GeneratorsAdminQuicktags

Quicktags Generator

Custom buttons for the Text tab of the classic editor, plus which core buttons to drop through the quicktags_settings filter.

acme-quicktags.php
Saved just now
Where the buttons load
Limit to post types
every editor screen
Your buttons
3 buttons
leadlead
ctacta
refref
Core buttons
all kept
Click a button to drop it from the toolbar through the quicktags_settings filter.
<?php
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
/**
 * Plugin Name:       acme quicktags
 * Description:       Adds 3 buttons to the Text tab of the classic editor.
 * Version:           1.0.0
 * Requires PHP:      7.4
 * Text Domain:       acme
 */

defined( 'ABSPATH' ) || exit;

/**
 * Print the Text tab buttons in the admin footer.
 *
 * wp_script_is() keeps this off every screen that never rendered an editor.
 */
function acme_quicktags_buttons() {
	if ( ! wp_script_is( 'quicktags' ) ) {
		return;
	}

	?>
	<script>
	( function () {
		if ( typeof QTags === 'undefined' ) {
			return;
		}

		QTags.addButton(
			'acme_lead',
			'lead',
			'<p class="lead">',
			'</p>',
			'',
			'Lead paragraph',
			1
		);

		QTags.addButton(
			'acme_cta',
			'cta',
			'[cta]',
			'[/cta]',
			'',
			'Call to action shortcode',
			205
		);

		QTags.addButton(
			'acme_ref',
			'ref',
			function () {
				var value = window.prompt( 'Footnote number' );

				if ( ! value ) {
					return;
				}

				QTags.insertContent( '<sup><a href="#fn-' + value + '">' + value + '</a></sup>' );
			},
			'',
			'',
			'Footnote reference',
			210
		);
	} )();
	</script>
	<?php
}
add_action( 'admin_print_footer_scripts', 'acme_quicktags_buttons' );