PhotoDune

How to check if widget is placed in sidebar or footer?

2079 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 10 and 49 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
+10 more
mpc moderator says

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…

254 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
PabloFierro says
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.

2358 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
digitalimpact says

Haven’t tested, but perhaps this would work?

2079 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 10 and 49 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
+10 more
mpc moderator says
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

2079 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 10 and 49 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
+10 more
mpc moderator says
digitalimpact said
Haven’t tested, but perhaps this would work?

Your link doesn’t work…

3256 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 more
ParkerAndKent says
mpc said
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

You should do that by CSS as proxdeveloper said ;)

Parker

4099 posts
  • 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
+9 more
Ivor moderator says
101 posts Too Much is Never Enough
  • Bought between 1 and 9 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 1-2 years
  • Referred between 100 and 199 users
  • Sold between 100 000 and 250 000 dollars
premitheme says
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 :)

660 posts
  • Elite Author
  • 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
  • Support Staff
+6 more
cudazi support says

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
}

via WordPress.org

254 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
PabloFierro says

I really think you should find another solution other than PHP for this.

by
by
by
by
by