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' );

About this generator

Quicktags Generator Online

Add buttons to the Text tab of the classic editor with QTags.addButton(). This generator writes all eight arguments in the right order — id, display label, opening tag, closing tag, access key, tooltip, priority and editor instance — and wraps them in the PHP that loads them safely, either printed in the admin footer behind a wp_script_is( 'quicktags' ) check or enqueued as a real file with quicktags as a dependency.

The Text tab toolbar is drawn live above the form, with your buttons in priority order alongside the core ones you kept, so you can see where a new button lands before pasting anything. Output as a snippet, a functions.php block, a plugin file, or a standalone quicktags.js. Free, no account, nothing uploaded.

Reviewed Output tested on WordPress 6.8 · PHP 8.3

Why the Quicktags Generator beats hand-writing QTags.addButton()

QTags.addButton() takes eight positional arguments with no names, and the two most useful of them — access key and priority — sit behind arguments you probably want to leave empty. Get the id wrong and you replace a core button instead of adding one. Get the loading wrong and QTags is not defined appears in the console on every screen that never rendered an editor. This generator handles the ordering, the ids and the loading.

Three button behaviours

Wrap the selection in an opening and closing tag, insert a one-shot string, or prompt for a value and substitute it into a template with %s. The prompt type is emitted as a real callback that calls window.prompt() and then QTags.insertContent(), with an early return when the user cancels.

Trailing arguments only when needed

The generator works out the last argument you actually set and stops there, so a simple wrap button is a single readable line instead of eight positional arguments padded with empty strings. Add a tooltip or a priority and the call expands to match.

Access keys checked against core

Core has already claimed b, i, a, q, d, s, m, u, o, l, c and t. Reuse one and the checker names the core button you are shadowing; assign the same key twice in your own set and that is an error. Multi-character keys are caught with a one-click trim.

Core ids protected

Registering a button with a core id such as strong or link replaces core's own button rather than adding one. The generator prefixes your ids automatically and flags any that would still collide, with a one-click fix.

Core buttons pruned through the right filter

Removing buttons is not done in JavaScript — it is the quicktags_settings filter rewriting the buttons string. The generator emits that filter with the kept ids in core order, optionally scoped to a single editor instance, and warns you if you remove the close button and strand authors mid-tag.

Loading that cannot fire too early

The inline build prints in admin_print_footer_scripts behind a wp_script_is( 'quicktags' ) check and an inner typeof QTags === 'undefined' guard. The file build enqueues on post.php, post-new.php and comment.php only, with quicktags as a script dependency so QTags always exists first.

How does the Quicktags Generator work?

Four steps: decide how the buttons load, define them, prune anything core adds that you do not want, then export.

  1. 01

    Choose how the buttons load

    Inline in the admin footer, or enqueued as js/quicktags.js with quicktags as a dependency. Optionally limit both to specific post types, and scope the buttons to a single editor instance id such as content.

  2. 02

    Add your buttons

    Start from a preset — lead paragraph, shortcode, callout, prompt — or add your own. Each button takes a label, an id, a behaviour, the tag or template to insert, an optional single-character access key, a tooltip and a priority. Core uses 10 to 200 in tens, so 205 puts you after everything.

  3. 03

    Prune the core buttons

    Untick any of core's thirteen buttons and the generator adds a quicktags_settings filter that rewrites the button list. The preview strip updates so you can see the toolbar the author will get.

  4. 04

    Check and export

    Clear the flagged issues — mismatched open and close tags, duplicate ids or access keys, a prompt template with no %s — then copy the PHP, or switch to the JavaScript tab for the standalone quicktags.js.

Worked example — two wrap buttons printed in the admin footer

The inline delivery mode. wp_script_is() keeps the script off every admin screen that never rendered an editor; the inner guard covers the case where the editor loaded without quicktags.

/**
 * 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>' );

		QTags.addButton( 'acme_cta', 'cta', '[cta]', '[/cta]' );
	} )();
	</script>
	<?php
}
add_action( 'admin_print_footer_scripts', 'acme_quicktags_buttons' );

Add a tooltip and a priority and the call expands to the full positional form: id, display, opening tag, closing tag, access key, title, priority, instance. Switch to the file delivery mode and the same JavaScript is emitted as js/quicktags.js, enqueued with array( 'quicktags' ) as its dependency.

Quicktags and the Text tab — frequently asked questions

The questions that come up when adding buttons to the classic editor.

Do quicktags work in the block editor?

No. Quicktags belong to the classic editor's Text tab. They still appear anywhere wp_editor() renders in classic mode — comment editing, many plugin screens, and the Classic block's own text view — but authors working in the block editor never see them. Check which editor your site actually uses before building buttons for it.

Why do I get "QTags is not defined"?

Your script ran before the quicktags script loaded, or on a screen where no editor was rendered at all. Fix it by enqueueing your file with array( 'quicktags' ) as its dependency, or by printing inline in admin_print_footer_scripts behind a wp_script_is( 'quicktags' ) check. A typeof QTags === 'undefined' guard inside the IIFE covers the rest.

How do I remove buttons from the Text tab?

Filter quicktags_settings and set $settings['buttons'] to a comma-separated list of the ids you want to keep — core reads that string rather than a removal list. The callback also receives the editor id, so you can prune a single instance and leave the others alone.

What do the eight arguments of QTags.addButton() mean?

In order: id (becomes qt_{editor}_{id} in the DOM), display label, opening tag or a callback function, closing tag, single-character access key fired with alt+shift, title attribute for the tooltip, priority, and the editor instance id. Pass an empty string for the instance and the button appears in every editor on the page.

How do I add a shortcode button to the editor?

Use a wrap button with the opening shortcode as the third argument and the closing shortcode as the fourth, for example [cta] and [/cta]. The button then toggles: it wraps the current selection, and clicking again after the opening tag closes it. For a self-closing shortcode use an insert button and leave the closing argument empty.

How do I prompt the user for a value before inserting?

Pass a function as the third argument instead of a string. Inside it call window.prompt(), return early if the user cancels, then insert with QTags.insertContent(). This generator writes that pattern from a template containing %s, substituting the answer at every occurrence — which is what a footnote reference needs, since the number appears in both the anchor and the label.

Where do I paste the code from the Quicktags generator?

You have three good options and one bad one. Best is a small site-specific plugin — the generator can output one for you, and it keeps working when you change theme. A code-snippets plugin is fine too. A child theme's functions.php works but ties the code to that theme. Never edit the parent theme: the next update overwrites it and your code is gone.

Can I use the generated code in client work or a commercial plugin?

Yes. The output is ordinary WordPress API calls that you configured — there is no licence attached to it and no attribution required. Use it in client sites, commercial plugins and themes, or products you sell. The generated file carries a short credit comment you are free to delete.

The other Admin generators in the library, plus the WordPress tools most often used alongside this one.