Articles of widgets

WordPress widget in custom theme

I created a custom theme and writing a basic widget for my wordpress based website. If I paste the code in functions.php the code works fine, however if I paste the code in a separate file and keep it in the plugins directory, it doesn’t show up in the admin > appearance > widgets. The […]

Removing side bar widgets from GovPress theme

I’m using the GovPress theme, I’ve created a child theme. I now want to remove the sidebar widgets, as they are no use to me. I’ve read multiple articles online, but none of them work. I believe I need to create a functions.php in my child theme, but what needs to go into this file?

Correct code to use php in text widget

This code is used to display php inside a text widget add_filter(‘widget_text’,’execute_php’,100); function execute_php($html){ if(strpos($html,”<“.”?php”)!==false){ ob_start(); eval(“?”.”>”.$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } I’m currently using it in my theme. I’m constantly looking for better ways to do things. Every google search and website returned tells you to use this code or code similiar to […]

Random sidebar/widget background

Does anyone have a clever idea to get a random/changing background for just the widget sidebar?

How to set the default value as the saved value once a form of widget is saved?

I tried doing this for the function form : <?php function form(){ //Set up some default widget settings. $defaults = array( ‘uid’ => __(‘121232’, ‘example’), ‘height’ => __(‘250px’, ‘example’), ‘width’ => __(‘170px’, ‘example’) ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for=”<?php echo $this->get_field_id( ‘uid’ ); ?>”><?php _e(‘User ID:’, ‘example’); ?></label> <input […]

Widgets not showing on sidebars

I have registered two sidebars in my theme using the function below, but none of the widgets shows up in the sidebars even though I can manage them in the dashboard: // register sidebars add_action( ‘widgets_init’, ‘my_register_sidebars’ ); function my_register_sidebars() { register_sidebar( array( ‘id’ => ‘sidebar-left’, ‘name’ => __( ‘sidebar-left’ ), ‘description’ => __( ‘A […]

What's the right way to share data between widgets?

I’ve got a few custom widgets in my site, which I’m targeting to specific tags. There may be a case where there may be an overlap in widget targeting, and the desirable behaviour may be to only show the first of the widgets that match to that section or tag. Therefore, when a match occurs […]

looping widgets to organize bootstrap grids

Using twitter bootsrap I want to grid my widgets if in the same position more widgets are present what I mean: having a registered widget register_sidebar(array( ‘name’ => __(‘Footer Top’, ‘roots’), ‘id’ => ‘footer-top’, ‘before_widget’ => ‘<div class=”footer_teaser %1$s %2$s”>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ‘<h3>’, ‘after_title’ => ‘</h3>’, )); how would I count and […]

Custom CSS for a particular text/html widget in WordPress

I have a couple of text widgets on my Home Sidebar. There is one text widget in particular that I want it to implement custom CSS written in my child theme rather than the default styling provided by the theme. Is that possible? If yes, how?

Instance not inserting data for widget

I am trying to create a widget for my website. This is my first instance of widget creation and I am really unsure as to what the issue is Here is my code as it stands: add_action( ‘widgets_init’, ‘wy_rss_widget’ ); function wy_rss_widget() { register_widget( ‘WY_rss_widget’ ); } class WY_rss_widget extends WP_Widget { function WY_rss_widget() { […]