Skip to content

Instantly share code, notes, and snippets.

@dragipostolovski
Last active May 15, 2021 06:19
Show Gist options
  • Save dragipostolovski/45b9755ed432e730031476ef1ac865a6 to your computer and use it in GitHub Desktop.
Save dragipostolovski/45b9755ed432e730031476ef1ac865a6 to your computer and use it in GitHub Desktop.
<?php
/** Enqueuing the Stylesheet for the CTA Button Shortcode */
function pe_cta_enqueue_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'pe_cta_button_shortcode') ) {
wp_register_style( 'pe-cta-stylesheet', plugin_dir_url( __FILE__ ) . 'css/pe-cta-style.css' );
wp_enqueue_style( 'pe-cta-stylesheet' );
}
}
add_action( 'wp_enqueue_scripts', 'pe_cta_enqueue_scripts');
<?php
/**
* [pe_cta_button_shortcode] returns the HTML code for a CTA Button.
* @return string Button HTML Code
*/
add_shortcode( 'pe_cta_button_shortcode', 'pe_cta_button' );
/**
* Create a CTA Button Shortcode.
*
* @param $atts
*
* @return string
*/
function pe_cta_button( $atts ) {
$a = shortcode_atts( array(
'link' => '#',
'id' => 'pe_cta_button',
'color' => 'blue',
'size' => '',
'label' => 'Button',
'target' => '_self'
), $atts );
return '<p><a href="' . esc_url( $a['link'] ) . '" id="' . esc_attr( $a['id'] ) . '" class="button ' . esc_attr( $a['color'] ) . ' ' . esc_attr( $a['size'] ) . '" target="' . esc_attr($a['target']) . '">' . esc_attr( $a['label'] ) . '</a></p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment