WordPress GuideBuild → Button Shortcode

WordPress button shortcode: How to add a button to your site

Your guide to bare metal management best practices.

Buttons are essential for guiding visitors to take action—click a link, submit a form, download a file. But WordPress doesn’t include a built-in button shortcode, which can make adding buttons outside the Block Editor more challenging.

Let’s walk through how button shortcodes work in WordPress, how to create them manually or with plugins, and how to customize them with different styles, links, and behaviors.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What is a button shortcode in WordPress?

Shortcodes in WordPress are small code snippets wrapped in square brackets, like

or [contact-form], that let you add dynamic features into posts, pages, or widgets without writing full HTML.

WordPress itself doesn’t include a default [button] shortcode, but many themes or plugins add their own. A button shortcode is essentially a way to insert a styled clickable button anywhere shortcodes are supported—even inside Classic Editor posts, sidebar widgets, or template files.

You might want to use a button shortcode if:

How to create a button shortcode manually

If you want full control or don’t want to install a plugin, you can add your own shortcode to create customizable buttons.

Step 1: Add the shortcode to your theme or custom plugin

Open your theme’s functions.php file (or a custom plugin) and add the following code:

function custom_button_shortcode($atts) {
    $atts = shortcode_atts([
        ‘text’ => ‘Click Me’,
        ‘url’ => ‘#’,
        ‘target’ => ‘_self’,
        ‘class’ => ‘custom-button’
    ], $atts, ‘mybutton’);
    return ‘<a href=”‘ . esc_url($atts[‘url’]) . ‘” target=”‘ . esc_attr($atts[‘target’]) . ‘” class=”‘ . esc_attr($atts[‘class’]) . ‘”>’ . esc_html($atts[‘text’]) . ‘</a>’;
}
add_shortcode(‘mybutton’, ‘custom_button_shortcode’);

This code creates a [mybutton] shortcode that accepts the following attributes:

Step 2: Use the shortcode in a post or widget

After adding the code, you can use the shortcode like this:

[mybutton text=”Buy Now” url=”https://example.com” target=”_blank” class=”blue-button”]

You can paste this into a Classic Editor post, a shortcode block, or a widget.

Customize your shortcode button with CSS

To style your button, add custom CSS targeting the class you set in the shortcode.

For example, in the WordPress Customizer under Appearance > Customize > Additional CSS, you might add:

.blue-button {
  background-color: #0073aa;
  color: #fff;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 4px;
  display: inline-block;
  transition: background-color 0.3s ease;
}

.blue-button:hover {
  background-color: #005f8d;
}

You can create multiple styles by using different class names like .green-button, .cta-button, etc.

Use a plugin to add button shortcodes (no code required)

Prefer to skip the code? Several plugins let you insert buttons with shortcodes using a visual interface.

Shortcodes Ultimate

Image

Shortcodes Ultimate adds a library of shortcodes, including a flexible button shortcode.

To use it:

You can also reuse these shortcodes in sidebars, reusable blocks, and template parts.

MaxButtons

Image

MaxButtons gives you a visual drag-and-drop button builder.

To use it:

MaxButtons is ideal if you want consistent branding across dozens of buttons.

Add buttons with Popup Maker

Popup Maker is best known for its popups, but it also includes a useful [popup_trigger] shortcode that acts like a button to open a popup.

This is perfect for:

After setting up your popup, use the shortcode like:

[popup_trigger id=”123″ tag=”button”]Join the Newsletter[/popup_trigger]

The id corresponds to your popup, and you can change tag=”button” to a or div depending on your styling.

Best practices for button shortcodes

Creating a button is easy, but making it effective takes a few extra steps:

Alternatives to shortcode buttons

You don’t have to use shortcodes for buttons. Other options include:

Use shortcodes when you need to repeat buttons, place them in sidebars or widgets, or maintain styling across a site.

Additional resources

How to build a WordPress site →

A complete beginner’s guide that covers 9 key steps to a successful launch

The WordPress category page: a complete guide →

Discover effective methods to create and customize category pages in WordPress for better content organization.















How to use WordPress Gutenberg blocks →

A complete beginner’s guide to Gutenberg blocks