I am creating a feature for my website using a WordPress shortcode. The shortcode is displays an HTML table that contains certain data.
I have enabled the short code for widget/sidebar and it is working fine in the widget.
The only problem is that my designer has created two different styles; one for post and another for widget. Is there any way to know that the code is being executed in sidebar or in post?
eg:
if(is_widget()){
//add stylesheet for widget here
}
else{
//add stylesheet for post here
}
Thank you
I am creating a feature for my website using a WordPress shortcode. The shortcode is displays an HTML table that contains certain data.
I have enabled the short code for widget/sidebar and it is working fine in the widget.
The only problem is that my designer has created two different styles; one for post and another for widget. Is there any way to know that the code is being executed in sidebar or in post?
eg:
if(is_widget()){
//add stylesheet for widget here
}
else{
//add stylesheet for post here
}
Thank you
Share Improve this question edited Dec 28, 2016 at 15:50 Jami Gibbs 7694 silver badges13 bronze badges asked Dec 28, 2016 at 15:40 SD433SD433 631 silver badge10 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 1Using conditional tag in_the_loop inside your shortcode function may serve the purpose.
if( in_the_loop() ) {
//add stylesheet for post/page here...
} else {
//add stylesheet for widget here...
}
[myshortcode type="post"]
wheretype
indicates if it's a "post" or "widget" format and then apply a style based on that attribute setting. – Jami Gibbs Commented Dec 28, 2016 at 16:19