Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
loading css only on page where plugin is used
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Toppa  
View profile  
 More options Apr 22, 7:38 am
From: Michael Toppa <pub...@toppa.com>
Date: Wed, 22 Apr 2009 07:38:04 -0400
Local: Wed, Apr 22 2009 7:38 am
Subject: [wp-hackers] loading css only on page where plugin is used
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. I've read
Vladimir Prelovac's tip related to this at
http://mashable.com/2009/03/25/wordpress-plugin-developer-tips/ (tip
number 8) and a few similar posts by others, but they're all talking
about loading scripts only on appropriate admin pages. My situation is
not for an admin page.

I tried calling template_redirect (which in turn calls wp_enqueue_style)
in my plugin after calling add_shortcode and setting a flag indicating
the presence of my shortcode, but that didn't work (my testing indicates
Wordpress fires template_redirect before add_shortcode - the order I
call them in doesn't matter). It may be that it's not possible to
determine whether to take an action in the head of a page based on an
action in the body. In that case I can ask my plugin users to provide
page/post id numbers in my plugin's settings menu, so its css doesn't
get loaded on every page. But if any of you know a way to enqueue a
stylesheet based on the presence of a shortcode, please fill me in. :-)

Thanks!

Mike T

http://www.toppa.com
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "RE [wp-hackers] loading css only on page where plugin is used" by Ozh
Ozh  
View profile  
 More options Apr 22, 7:50 am
From: "Ozh" <o...@planetozh.com>
Date: Wed, 22 Apr 2009 13:50:00 +0200
Subject: RE [wp-hackers] loading css only on page where plugin is used
wp-hackers-boun...@lists.automattic.com a écrit sur 22/04/2009 13:38:04 :

> 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.

If you want to load the style only on some pages, maybe you can add it
inline? If so, testing the presence of the shortcode in each post is easy
(and you can also make it so it loads once in case multiple posts are
displayed)

Ozh

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Toppa  
View profile  
 More options Apr 22, 8:48 am
From: Michael Toppa <pub...@toppa.com>
Date: Wed, 22 Apr 2009 08:48:59 -0400
Local: Wed, Apr 22 2009 8:48 am
Subject: RE [wp-hackers] loading css only on page where plugin is used
Thanks for the reply Ozh - inline styling could work but would be really
ugly, as my plugin involves a fairly heavily styled form that uses an
ordered list for organizing the form elements. It would also mean users
would have to hack my code if they wanted to customize the display (I
suppose I could put in placeholder class declarations too, but then
we're getting into a workaround on top of a workaround). Mike T Date:
Wed, 22 Apr 2009 13:50:00 +0200 From: "Ozh" <o...@planetozh.com> Subject:
RE [wp-hackers] loading css only on page where plugin is used To:
wp-hack...@lists.automattic.com Message-ID:
<OF6660D081.F3C53FEC-ONC12575A0.0040D66D-C12575A0.00410...@notes.edfgdf.fr>
Content-Type: text/plain; charset="ISO-8859-1"
wp-hackers-boun...@lists.automattic.com a écrit sur 22/04/2009 13:38:04 :

> > 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.

If you want to load the style only on some pages, maybe you can add it
inline? If so, testing the presence of the shortcode in each post is easy
(and you can also make it so it loads once in case multiple posts are
displayed)

Ozh

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "loading css only on page where plugin is used" by aesqe
aesqe  
View profile  
 More options Apr 22, 10:14 am
From: aesqe <ae...@skyphe.org>
Date: Wed, 22 Apr 2009 16:14:36 +0200
Local: Wed, Apr 22 2009 10:14 am
Subject: Re: [wp-hackers] loading css only on page where plugin is used
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
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron D. Campbell  
View profile  
 More options Apr 22, 1:18 pm
From: "Aaron D. Campbell" <aa...@xavisys.com>
Date: Wed, 22 Apr 2009 10:18:22 -0700
Local: Wed, Apr 22 2009 1:18 pm
Subject: Re: [wp-hackers] loading css only on page where plugin is used
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.

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joost de Valk  
View profile  
 More options Apr 22, 1:40 pm
From: Joost de Valk <jo...@yoast.com>
Date: Wed, 22 Apr 2009 19:40:11 +0200
Local: Wed, Apr 22 2009 1:40 pm
Subject: Re: [wp-hackers] loading css only on page where plugin is used
Wouldn't that break XHTML validity?

On 22 apr 2009, at 19:18, "Aaron D. Campbell" <aa...@xavisys.com> wrote:

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aesqe  
View profile  
 More options Apr 22, 5:12 pm
From: aesqe <ae...@skyphe.org>
Date: Wed, 22 Apr 2009 23:12:03 +0200
Local: Wed, Apr 22 2009 5:12 pm
Subject: Re: [wp-hackers] loading css only on page where plugin is used
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:

--
-._______________KAWAII!_______________.-
Skyphe.org : It'll all make sense one day
http://skyphe.org .:. http://breedart.org
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron D. Campbell  
View profile  
 More options Apr 22, 8:20 pm
From: "Aaron D. Campbell" <aa...@xavisys.com>
Date: Wed, 22 Apr 2009 17:20:22 -0700
Local: Wed, Apr 22 2009 8:20 pm
Subject: Re: [wp-hackers] loading css only on page where plugin is used
I mean using the WP_Query class to create a query that is NOT stored in
the $wp_query global.  For example:

$queryArgs = array(
    'nopaging'        => true,
    'post_type'        => 'any',
    'post_status'    => 'draft,pending,future,publish'
);
$myQuery = new WP_Query($queryArgs);
if ($myQuery->have_posts()) {
    while ($myQuery->have_posts()) {
        $post = $myQuery->next_post();
        // Do something with $post
    }

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google