Skip to content

Instantly share code, notes, and snippets.

@benjamenjohnsondev
Created September 26, 2017 13:25
Show Gist options
  • Select an option

  • Save benjamenjohnsondev/31432c268c2970c0e7ad8c917957aa82 to your computer and use it in GitHub Desktop.

Select an option

Save benjamenjohnsondev/31432c268c2970c0e7ad8c917957aa82 to your computer and use it in GitHub Desktop.
Add classes to wp links with shortcode
<?php
function button_shortcode( $atts , $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'url' => '/',
'class' => 'class',
),
$atts
);
return '<a href="'. $atts['url'] .'" class="'. $atts['class'] .'">'. $content .'</a>';
}
add_shortcode( 'button', 'button_shortcode' );
//[button url="/somewhere" classes="over the"]rainbow[/button]
// will output: <a href="/somewhere" class="over the">rainbow</a>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment