Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cool_Shortcode_Name {
- static $add_script;
- static function init() {
- add_shortcode('cool_shortcode_name', array(__CLASS__, 'handle_shortcode'));
- add_action('init', array(__CLASS__, 'register_script'));
- add_action('wp_footer', array(__CLASS__, 'print_script'));
- add_action('wp_footer', array(__CLASS__, 'internal_script') );
- }
- static function handle_shortcode($raw_atts) {
- self::$add_script = true;
- $atts = shortcode_atts( array(
- 'argument' => 'default',
- ), $raw_atts, 'cool_shortcode_name' );
- ob_start();
- ?>
- <div>
- Template!
- </div>
- <?php
- $content = ob_get_clean();
- return $content;
- }
- static function register_script() {
- //wp_register_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0', 'screen' );
- //wp_register_script('imagesloaded', '//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.js', array('jquery'), '3.0.4', true);
- }
- static function print_script() {
- if ( ! self::$add_script )
- return;
- //wp_print_styles('font-awesome');
- //wp_print_scripts('imagesloaded');
- }
- static function internal_script() {
- if ( ! self::$add_script )
- return;
- ?>
- <script type="text/javascript">
- // Javascript goes here
- </script>
- <style>
- /* CSS Goes Here */
- </style>
- <?php
- }
- }
- Cool_Shortcode_Name::init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement