[wp-hackers] loading css only on page where plugin is used

aesqe aesqe at skyphe.org
Wed Apr 22 14:14:36 GMT 2009


Michael, try using something like this:

function shortcode_css()
{
   global $wp_query;
	
   if( !empty($wp_query->posts) )
   {
     foreach( $wp_query->posts as $post )
     {
       if(preg_match("#\[your_shortcode[^\]]*\]#is", $post->post_content)
         wp_enqueue_style( "your css name", "your css location" );
     }
   }
}
add_action('wp_print_styles', 'shortcode_css');

On 22.4.2009 13:38, Michael Toppa wrote:
> Hi all,
>
> I'm working on a plugin that uses a shortcode. I want to load a css file
> for the plugin only for posts or pages that use the shortcode.
-- 
-._______________KAWAII!_______________.-
Skyphe.org : It'll all make sense one day
http://skyphe.org .:. http://breedart.org


More information about the wp-hackers mailing list