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

aesqe aesqe at skyphe.org
Wed Apr 22 21:12:03 GMT 2009


sorry for asking what might seem like a pretty dumb question, but what 
kind of custom query? could you give an example? :/

On 22.4.2009 19:18, Aaron D. Campbell wrote:
> That will only work with the default queries, if someone does a custom
> query it won't catch it. I'd recommend the inline idea and just set a
> flag so the styles are only added once.
>
> aesqe wrote:
>> 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.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.287 / Virus Database: 270.12.2/2072 - Release Date: 04/21/09 16:48:00
>

-- 
-._______________KAWAII!_______________.-
Skyphe.org : It'll all make sense one day
http://skyphe.org .:. http://breedart.org


More information about the wp-hackers mailing list