Button shortcode
Type [button url="/contact/"]Get in touch[/button] to add a button that looks like your theme’s buttons.
<?php
// [button url="/contact/" new_tab="no"]Get in touch[/button]
$atts = shortcode_atts( array( 'url' => '#', 'new_tab' => 'no' ), $atts, 'button' );
$tab = 'yes' === $atts['new_tab'] ? ' target="_blank" rel="noopener"' : '';
$text = '' !== trim( (string) $content ) ? $content : __( 'Read more' );
return '<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="' . esc_url( $atts['url'] ) . '"' . $tab . '>' . esc_html( $text ) . '</a></div>';
Good to know
Add new_tab="yes" to open the link in a new tab.
How to use it
Type [button] in a post, a page or a Shortcode block.
In these packs
- Shortcodes: Handy shortcodes for dates, breadcrumbs, buttons, share links, members-only content and more.