2

I'm developing a theme that has more than 5 different sidebars and I want to apply a function to a particular one of them for styling purposes. Basically, the function will modify it's params using a counter to show random 's between each of the widgets. I came up with that:

function widget_params( $params ) { 
    // ...
}
add_filter( 'dynamic_sidebar_params', 'widget_params' );

But however, it will run for each and every different sidebar. Is there any way to make it work only on a particular sidebar? Or alternatively, is there any way to get current widget's sidebar id inside of that function?

Hope all of that makes sense.

Thanks in advance!

1 Answer 1

7

If you were to add var_dump($params); to the top of your callback you'd notice that it contains references to both the sidebar name and the sidebar ID. You can use those to control when this runs, provided you know the name or ID.

function widget_params( $params ) { 
  if ('Main Sidebar' === $params[0]['name']) {
    // do something
  }
  return $params;
}
add_filter( 'dynamic_sidebar_params', 'widget_params' );
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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