Skip to content

Instantly share code, notes, and snippets.

@UeldoTheme
Last active April 10, 2019 19:50
Show Gist options
  • Save UeldoTheme/c28ece170201d9c0bd4e2fa8550e9dc6 to your computer and use it in GitHub Desktop.
Save UeldoTheme/c28ece170201d9c0bd4e2fa8550e9dc6 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Custom Buttons Shortcode
Description: Add buttons to your WordPress website with single simple shortcode
Author: Martanian <support@martanian.com>
Author URI: http://themeforest.net/user/martanian
Version: 1.0
*/
add_shortcode( 'custom_buttons_shortcode', 'custom_buttons_shortcode_func' );
function custom_buttons_shortcode_func( $atts, $content = null ) {
extract( shortcode_atts( array(
'href' => '#',
'target' => '_blank',
'class' => ''
), $atts ));
return( '<div class="custom-buttons-shortcode-container"><a href="'. esc_url( $href ) .'" target="'. esc_attr( $target ) .'" class="custom-buttons-shortcode '. esc_attr( $class ) .'">'. do_shortcode( $content ) .'</a></div>' );
}
add_action( 'wp_enqueue_scripts', 'custom_buttons_shortcode_styles' );
function custom_buttons_shortcode_styles() {
wp_enqueue_style( 'custom-buttons-shortcode-style', plugin_dir_url( __FILE__ ) .'style.css' );
}
?>
# all params example
[custom_buttons_shortcode href="http://example.com" target="_self" class="extra-class"]Hello![/custom_buttons_shortcode]
# only "href" is required
[custom_buttons_shortcode href="http://example.com"]Hello![/custom_buttons_shortcode]
.custom-buttons-shortcode-container {
margin: 30px 0;
}
.custom-buttons-shortcode-container .custom-buttons-shortcode {
display: inline-block;
text-align: center;
padding: 10px 25px;
background: #e73a30;
color: #fff;
font-size: 17px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
border-bottom: 2px solid #b7241b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment