Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Created August 29, 2017 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raftaar1191/905ca4430d6a4457bb248f0b3ebc67fb to your computer and use it in GitHub Desktop.
Save raftaar1191/905ca4430d6a4457bb248f0b3ebc67fb to your computer and use it in GitHub Desktop.
Adding script with Shortcode
<?php
/**
* Register Scripts
*
*/
function be_register_scripts() {
wp_register_style( 'be-shortcode', get_stylesheet_directory_uri() . '/assets/css/shortcode.css' );
wp_register_style( 'be-shortcode-color1', get_stylesheet_directory_uri() . '/assets/css/color1-shortcode.css' );
wp_register_style( 'be-shortcode-color2', get_stylesheet_directory_uri() . '/assets/css/color2-shortcode.css' );
wp_register_style( 'be-shortcode-color3', get_stylesheet_directory_uri() . '/assets/css/color3-shortcode.css' );
wp_register_style( 'be-shortcode-color4', get_stylesheet_directory_uri() . '/assets/css/color4-shortcode.css' );
}
add_action( 'wp_enqueue_scripts', 'be_register_scripts' );
/**
* My Shortcode
*
*/
function be_shortcode( $atts = array() ) {
$color = '';
if ( $atts['color'] ) {
$color = '-' . $atts['color'];
}
wp_enqueue_style( 'be-shortcode' . $color );
return 'Hello World';
}
add_shortcode( 'be_shortcode', 'be_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment