WordPress Custom QuickTags: How to Add Them

The WordPress QuickTags API is a powerful tool that allows you to add buttons to the WordPress admin text editor. While the rich editor is more commonly used, adding quick tags can be incredibly useful for repetitive tasks. In this article, we will explore the default quick tags provided in WordPress and how to create your own custom quick tags.

Default Quick Tags in WordPress

WordPress comes with a variety of default quick tags that you can use to format your content quickly and easily. These include:

– Bold: Adds bold formatting to selected text.

– Italic: Adds italic formatting to selected text.

– Link: Inserts a hyperlink to selected text.

– Blockquote: Formats selected text as a blockquote.

– Strikethrough: Adds a strikethrough effect to selected text.

– Code: Formats selected text as code.

– Ordered List: Creates an ordered list.

– Unordered List: Creates an unordered list.

– Spellcheck: Checks the spelling of selected text.

Creating Custom Quick Tags

To create your own custom quick tags, you need to hook a custom function to the admin_print_footer_scripts hook. This allows you to add custom JavaScript code within the admin footer. The QuickTags API provides a built-in function called addButton that you can use to create your own quick tags.

The addButton function accepts eight arguments:

– id: (string) (required) The HTML ID for the button.

– display: (string) (required) The HTML value for the button.

– arg1: (string) (required) Either a starting tag to be inserted like “” or a callback that is executed when the button is clicked.

– arg2: (string) (optional) Ending tag like “”. Leave empty if tag doesn’t need to be closed (i.e. “


”).

– access_key: (string) (optional) Shortcut access key for the button.

– title: (string) (optional) The HTML title value for the button.

– priority: (int) (optional) A number representing the desired position of the button in the toolbar. 1 – 9 = first, 11 – 19 = second, 21 – 29 = third, etc.

– instance: (string) (optional) Limit the button to a specific instance of Quicktags, add to all instances if not present.

Here is an example of how to add a custom quick tag that inserts a link to WPExplorer:

// Add buttons to HTML editor

add_action(‘admin_print_footer_scripts’,’rc_quicktags’);

function rc_quicktags() { ?>

}

To use this custom quick tag, simply click on it once to insert the beginning of the tag. Then add your desired text and click the button again to add the closing tag.

Conclusion

The QuickTags API is a powerful tool that allows you to add custom buttons to the WordPress admin text editor. By creating your own custom quick tags, you can save time and streamline your content creation process. If you have any questions or recommendations, please leave a comment below!

Stay in Touch

spot_img

Related Articles