How to add class on Widget Title

Two approaches: Don’t bother Just target .widget.{dynamic-class} h3 instead Use %2$s I don’t know if this will work, but try: ‘before_title’ => ‘<h3 class=”%2$s”>’ But personally, I’d go with the former option. You’ve already got a unique class name; just leverage the element hierarchy to apply styles selectively.

Display all posts with same title

Lets use the build in features WordPress has to offer. It is almost always not adviced to use custom SQL whenever WordPress offers native functions to perform the specific duty. To query our posts, we will make use of WP_Query. The only problem is, WP_Query does not support the feature where we look for posts … Read more

Adding classes to dynamic sidebar

You haven’t actually said what the problem is. But I can see one for starters – dynamic_sidebar in your if conditions will echo out the widgets immediately. If you want to check a sidebar has widgets, use is_active_sidebar: is_active_sidebar( ‘sidebar-1’ ); // True/false

WordPress widget in custom theme

You have to hook your widget registering like that: add_action(“widgets_init”, “register_widgets”);// Hook WP /** * Register widgets */ function register_widgets() { require_once “FooWidget.php”; register_widget(“FooWidget”); } Same for the widget zones add_action(“widgets_init”, “register_widgets_zones”); function register_widgets_zones() { register_sidebar(array( “name” => “Foo Zone Page”, “id” => “foo-zone-widgets”, “class” => “panel”, “before_widget” => ‘<div id=”%1$s” class=”widget %2$s”>’, “after_widget” => … Read more

Display specific widgets in different area’s around the page

You will want to create a new widget area or dynamic sidebar in your theme’s code. Justin Tadlock has a great tutorial about how to do this, but the basics boil down to this. Add the widget area declaration in your theme’s functions.php file: <?php add_action(‘widgets_init’, ‘my_register_sidebars’); function my_register_sidebars() { /* Register the ‘cartwidgets’ sidebar. … Read more

Custom Widget outputs the input but doesn’t save anything inside the textarea

Your primary issue isn’t with saving the data but displaying in the form if it has been saved. I rewrote the offending function: function form($instance) { $title = strip_tags( $instance[‘title’] ); $info = esc_textarea( $instance[‘info’] ); // var_dump($instance); // debug ?> <p> <label for=”<?php echo $this->get_field_id(‘title’); ?>”><?php _e(‘Title:’); ?></label> <input class=”widefat” id=”<?php echo $this->get_field_id(‘title’); ?>” … Read more