Filter Text from sidebar widget?

In the method “widget” look for the line that sets the category then add either: $cat = empty($instance[‘cat’]) ? ‘N/A’ : $instance[‘cat’]; (where you replace N/A with something you like) or… better… add a filter instead like this: $cat = apply_filters( ‘widget_my_cat’, empty($instance[‘cat’]) ? ‘N/A’ : $instance[‘cat’], $instance, $this->id_base); And then hook into ‘widget_my_cat’ to … Read more

Widget’s container?

It’s the default behavior of a dynamic sidebar to output li tags around widgets. You can override that though in the sidebar declaration. You would do that by passing the sidebar registration the following additional arguments: register_sidebar( array( ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’, ‘after_widget’ => “</div>” ) );

How to load a stylesheet into wp_head from a custom widget?

There are various approaches (including this one), but you could consider, since you’re talking about a stylesheet and not a script, simply enqueueing it from the Plugin, regardless of whether the Widget is active. (Which is worse: the few bytes of Widget-specific CSS, or the server overhead to determine if the Widget is active?) Just … Read more

Is there a simple way to have a new sidebar for each page?

Registering sidebar is just a function call, there is no reason it can’t be run on top of some logic. Here is code I wrote (and use) in my current theme: $pages = get_pages(); foreach ( $pages as $page ) { register_sidebar( array( ‘name’ => “Page: {$page->post_title}”, ‘id’ => “sidebar-page-{$page->post_name}”, ‘description’ => “Widgetized area after … Read more

change widget to display excerpt instead of content

I dont see anywhere on the code that it adds either full text or excerpt. So I decided to test the widget and that’s exactly what I got. There is no post content being output. So my suggestion is to just add <?php the_excerpt(); ?> Wherever you want it to output… eg just after the … Read more