Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <? php
- add_shortcode('example', function( $atts ) {
- //extracting the shortcode attributes
- extract( shortcode_atts( array(
- 'value1' => null,
- 'value2' => null,
- 'value3' => null
- ), $atts ) );
- //Now here I wll do my code for the shortcode
- // But the shortcode needs some js and css to work
- // so, I'm trying like this
- });
- add_action ('wp', 'add_shortcode_script');
- function add_shortcode_script () {
- global $post;
- if ( empty($posts) )
- return $posts;
- $flag = false;
- foreach ($posts as $post) {
- if ( stripos($post->post_content, '[EXAMPLE') )
- $flag = true;
- break;
- }
- if ($flag){
- $custom_script = '<script type="text/javascript">
- var a = '. $value3 .'
- </script>';
- $custom_style = '<style type="text/css">
- .class {
- background-color: '. $value2 .';
- }
- </style>';
- // But I'm not sure how you propose to fetch the shortcode variables like $value2, $value3 here
- wp_add_inline_script ('my_script', $custom_script);
- wp_add_inline_style ('my_style', $custom_stle);
- }
- return $posts;
- }
Add Comment
Please, Sign In to add comment