Articles of widgets

disbale default widgets on theme activation

I want to deactivate all default widgets on theme activation which are active by default for new WordPress installation. I’m using following function as callback for theme activation : if ( is_admin() && isset($_GET[‘activated’] ) && $pagenow == ‘themes.php’ ) { // } By default activated widgets are : Search Recent Posts Recent Comments Archives […]

How to use get_results() in widget front end?

I’m trying to get_results() in my widget’s front end, this is my current code: public function widget( $args, $instance ) { echo $args[‘before_widget’]; if($children = $wpdb->get_results( “SELECT ID FROM $wpdb->posts” )) echo “working”; echo $args[‘after_widget’]; } However I’m getting error “Fatal error: Call to a member function get_results() on a non-object”. I need to access […]

How to best include widget area just on homepage?

I have a front-page.php defining the homepage of my theme (a Genesis child theme). In it, I have some custom widget areas, like so: genesis_register_sidebar( array( ‘id’ => ‘cta’, ‘name’ => __( ‘How do I Connect?’, ‘site’ ), ‘description’ => __( ‘This is the cta widget for the home page.’, ‘site’ ), ) ); add_action( […]

Customizing the Widget content markup

I am using bootstrap to create panels for the sidebar widgets, and I can set the container markup for the widget, as well as the markup for the panel header, but I cannot provide the markup for the panel content. I have this so far: register_sidebar(array( ‘name’ => __(‘Right Sidebar’), ‘id’ => ‘home_right_1’, ‘before_widget’ => […]

wp_dropdown_pages in widget form

I have a small quirk somewhere in my widget form. Upon saving the widget instance, the form refreshes with the wrong selected ‘page_id’ from the wp_dropdown_pages input. If I refresh the widgets page, the correct, saved page_id is selected in the dropdown. Here’s the portion of code: public function form( $instance ) { if( isset( […]

Add Shortcode tag in Widget/Sidebar

I want to add a shortcode tag in the sidebar/widget. I am able to get the required functionality if I add the code in the theme’s function.php add_filter(‘widget_text’, ‘do_shortcode’); My problem is that I am searching for a way I can do this from the plugins files itself without affecting any of the theme files. […]

How to include a file only on dashboard widgets page?

I want to add some styles to the widgets input fields. Therefore I want to include a style.css file only on the wp-admin/widgets.php page. How can I detect the above page and include file there?

How to change the default class for the widget title?

I would like to change the default class of the widget title. Currently it is h2 and I would like it to be h3. I have seen there is the option of customizing css so that h2 looks like h3. #sidebar h2 { font-size: 24px; } But then, this may cause a problem if I […]

register_sidebar fails when using a include within functions.php

I have registered several sidebars via functions.php like this: // Register sidebars function register_widgets() { // Main sidebar register_sidebar( array( ‘name’ => __( ‘Main Sidebar’, ‘Core’ ), ‘id’ => ‘main’, ‘description’ => __( ‘The main sidebar appears on the right on each page except the front page template and blog.’, ‘Core’ ), ‘before_widget’ => ‘<aside […]

How to use wordpress content class?

<div class=”sidebar_area”> <h4>Sponsor</h4> <div class=”sidebar_content”> <ul> <li><a href=”#”>This is new post</a></li> <li><a href=”#”>This is new post</a></li> <li><a href=”#”>This is new post</a></li> <li><a href=”#”>This is new post</a></li> <li><a href=”#”>This is new post</a></li> <li><a href=”#”>This is new post</a></li> </ul> </div> I like to make my widget like this code. But problem is here I can’t use widget […]