- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Hi, I am creating some custom widgets and I would like to check inside the widget is it placed in the footer or sidebar, any idea how to do this?. The heading looks different for footer and sidebar…
mpc said
Hi, I am creating some custom widgets and I would like to check inside the widget is it placed in the footer or sidebar, any idea how to do this?. The heading looks different for footer and sidebar…
Using ? javascript ? css ?
It’s easy task for both cases, you simply do a child search for ”.widget” inside your footer or sidebar elements.
Haven’t tested, but perhaps this would work?
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
proxdeveloper said
mpc said
Hi, I am creating some custom widgets and I would like to check inside the widget is it placed in the footer or sidebar, any idea how to do this?. The heading looks different for footer and sidebar…Using ? javascript ? css ?
It’s easy task for both cases, you simply do a child search for ”.widget” inside your footer or sidebar elements.
PHP
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
digitalimpact said
Haven’t tested, but perhaps this would work?
Your link doesn’t work…
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Interviewed on the Envato Notes blog
- Author was Featured
- Item was Featured
- Beta Tester
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
mpc said
proxdeveloper saidPHP
mpc said
Hi, I am creating some custom widgets and I would like to check inside the widget is it placed in the footer or sidebar, any idea how to do this?. The heading looks different for footer and sidebar…Using ? javascript ? css ?
It’s easy task for both cases, you simply do a child search for ”.widget” inside your footer or sidebar elements.
You should do that by CSS as proxdeveloper said 
Parker
- Envato Staff
- Reviewer
- Community Moderator
- Venezuela
- Has been a member for 4-5 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Microlancer Beta Tester
- Sold between 10 000 and 50 000 dollars
- Exclusive Author
if ( is_active_sidebar(footer-sidebar) ) {
// Display footer sidebar
} else {
// Display none
};
Ref: http://codex.wordpress.org/Function_Reference/is_active_sidebar & http://core.trac.wordpress.org/browser/tags/3.2.1/wp-content/themes/twentyten/sidebar-footer.php
Ivor said
if ( is_active_sidebar(footer-sidebar) ) { // Display footer sidebar } else { // Display none };Ref: http://codex.wordpress.org/Function_Reference/is_active_sidebar & http://core.trac.wordpress.org/browser/tags/3.2.1/wp-content/themes/twentyten/sidebar-footer.php
I think he needs to achieve something different. As I understand he want to check if a specific widget is displayed in specific widgetized area. I needed something like that for the case below:
I’m using [embed] shortcode in a custom video widget, and sidebar width was 200px but the footer widgets column’s width was 230px so I wanted to return [embed width="200"]video url[/embed] if it’s displayed in the sidebar but return [embed width="230"]video url[/embed] if it’s displayed in the footer.
i didn’t find a PHP solution, and used the javascript way.
mbc said
The heading looks different for footer and sidebar…
If you mean the styling of the heading, so you need to go CSS , for example…
#footer .widget-class .heading-class { /* footer heading style */ }
#sidebar .widget-class .heading-class { /* sidebar heading style */ }
Anybody have PHP solution for my case would be appreciated 
- Sold between 250 000 and 1 000 000 dollars
- Referred between 500 and 999 users
- Envato Staff
- Author had a File in an Envato Bundle
- Has been a member for 4-5 years
- Author was Featured
- Support Staff
- Was featured in a podcast
Haven’t tested this but…
$widget_id = 'your_unique_widget_id';
$sidebar_id = 'my_sidebar_id'
$sidebar_widgets = get_option('sidebars_widgets');
foreach ($sidebar_widgets[$sidebar_id] as $widget)
if (strpos($widget, $widget_id) !== false)
$success = true;
if ($success !== true) {
//whatever
}
I really think you should find another solution other than PHP for this.
