Image picker widget

Try this code. class Image_Picker extends WP_Widget { function Image_Picker() { $widget_ops = array(‘classname’ => ‘Image_Picker’, ‘description’ => ‘Pick 2 images from media library’); $this->WP_Widget(‘Image_Picker’, ‘Image Picker’, $widget_ops); } function form($instance) { //WIDGET BACK-END SETTINGS $instance = wp_parse_args((array) $instance, array(‘link1’ => ”, ‘link2’ => ”)); $link1 = $instance[‘link1’]; $link2 = $instance[‘link2’]; $images = new WP_Query( … Read more

Setting up widgets in wordpress with a unique ID for the after_title argument

Looking at widget.php in trac sprintf() only runs on before_widget (Line 884): $params[0][‘before_widget’] = sprintf($params[0][‘before_widget’], $id, $classname_); Hence, it won’t work for any of the other arguments. I wondered whether you could use the dynamic_sidebar_params filter, but the $id and $classname_ arguments aren’t passed on to the filter. Outside of hacking core, I’m not sure … Read more

How do I register a stylesheet inside a WordPress widget?

wp_enqueue_scripts is called way before WordPress processes the widget content, so just as in this post, you’ve missed the boat :). Instead, just call wp_enqueue_style directly: function widget($args, $instance) { wp_enqueue_style( ‘myprefix-style’, plugins_url(‘mystyle.css’, __FILE__) ); //Widget content } (no need to register if you’re just going to enqueue it straight after). Same works for wp_enqueue_script.

How to insert widget areas specific to certain pages (or posts, etc.)?

Use Conditional Tags to show content only if a certain condition is met. In your case, you’re probably looking to use is_front_page(). <aside> <ul> <?php if ( function_exists( ‘dynamic_sidebar’ ) ) { if ( is_front_page() ) { if ( ! dynamic_sidebar( ‘frontpage-widget-area’ ) ) { echo ‘<li>No sidebars for the frontpage.</li>’; // some default output … Read more

including image assets in widget

It sounds like you’ll need the plugins_url() function which generates the URL for the plugins directory and can handle any alternate configuration (such as if you moved it to the /mu-plugins/ directory, a personal favorite of mine). The Codex documentation is good, but here’s a quick example. Let’s say you’re making this in a plugin … Read more

How do I add Widgets to my theme and activate them on my site?

It sounds like you’re trying to add a new widget area (dynamic sidebar) to your Theme. That process has three parts: Register the dynamic sidebar in functions.php, using register_sidebar(): function wpse121723_register_sidebars() { register_sidebar( array( ‘name’ => ‘Home right sidebar’, ‘id’ => ‘home_right_1’, ‘before_widget’ => ‘<div>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ‘<h2 class=”rounded”>’, ‘after_title’ => ‘</h2>’, … Read more

Widget options get

Widget data is stored in the options table as a two dimensional array. All data for the same type of widget is stored under the same option key. The key of the outer array is a kind of widget “index”– the identifier for the particular instance of the widget. The inner arrays contain the individual … Read more