Color Picker Showing Twice When Widget Added to Sidebar

I added code from this example and it works! (wp 9 still has same issue with color picker) <script> ( function( $ ){ function initColorPicker( widget ) { widget.find( ‘.color-picker’ ).wpColorPicker( { change: _.throttle( function() { // For Customizer $(this).trigger( ‘change’ ); }, 3000 ) }); } function onFormUpdate( event, widget ) { initColorPicker( widget … Read more

Best way to add internal link in widget

The page ID can vary in different installation, and it can’t be changed, so an option is to use get_page_by_path because the page slug can be easily changed: <div class=”my-link-box”> <?php $page = get_page_by_path(‘my-page’); ?> <a href=”https://wordpress.stackexchange.com/questions/126876/<?php echo get_permalink($page); ?>”><?php echo $page->post_title; ?></a> </div> However this is not a great solution as well. Once you … Read more

How to check if a widget has no title

Nope, there is no way (thank I can think of) to do this cleanly. Handling of output and related parameters is up to the each wdiget’s individual widget() method. There is no generic way to manipulate it. You could maybe get away with filtering widget save or display instances to force it to always have … Read more

Check which registered sidebar a widget is added to

There isn’t a standard way to do it AFAIK in the form() method; here’s a function to do it: function wp158055_get_sidebar_id( $widget ) { foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { if ( array_search( $widget->id, $widget_ids ) !== false ) return $sidebar_id; } return false; } And call with $this. Note from the … Read more

How do you create dynamic customised sections in WordPress?

One common way to do similar task is creating a page template. For example: <?php /* Template Name: Reviews and Quotes */ get_header(); ?> <div id=”content”> <div id=”reviews”> <?php $reviews = get_the_reviews(); foreach( $reviews as $review ) { <?php <div class=”review”> ….. </div> ?> } ?> </div> <div id=”quotes”> <?php $quotes = get_the_quotes(); foreach( $quotes … Read more

instance is empty in function widget()

Your widget really has a lot of issues and completely breaks my layout on my back-end widget page. I suggest that you start at the Widget API to learn the proper way how to code a widget Here is a couple of issues I have picked up: Reputable sources should not be suggesting or even … Read more

Warning: Missing argument 2 for widget_title filter

You don’t pass more than argument to that filter, so any callback expecting more than one will not get it. The core calls this filter always like this: $title = apply_filters( ‘widget_title’, empty($instance[‘title’]) ? ” : $instance[‘title’], $instance, $this->id_base ); But you are passing just $instance[‘title’]. Add the missing parameters, and the error will vanish. … Read more

How to run PHP code in Text Widget with no plugin in WP 4.4

Better to write your own widget that does precisely what you need instead of something like this. However, if you really want to execute arbitrary PHP in a widget, use a plugin specifically designed for that task: https://wordpress.org/plugins/php-code-widget/ I maintain this plugin specifically so that people don’t resort to doing things like what you have … Read more