0

I have a theme that uses registers a sidebar called 'homepage-middle-widget' and it's child widgets are pulling images in undesired sizes. Is it possible to target a widget and / or it's parent in PHP? I was thinking something like:

if (is_home() && widget_name == 'foo-widget' && sidebar_name == 'homepage-middle-widget'): 
/*run this code*/; 
else: /*run default code*/;
endif;

I can't seem to find anything in the codex about targeting specific sidebar names or widgets by placement.

The alternative would be writing a new widget, I suppose.

0

You can write the logic inside widget functions. When the widget is added in sidebar, it will check for sidebar name and home page.

   global $wp_registered_widgets, $wp_registered_sidebars;
   $sidebars_widgets = get_option('sidebars_widgets');
   if($sidebars_widgets["sidebar-1"] && is_home()) 
   {
      //Write your logic here
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.