How to get options of all active widgets ?

This actually seems like a quite plausible approach – to me. There is nothing wrong with looping through it, sometimes it is the only/fastest way anyway. I don’t know how you get your sidebars, but for this $sidebars_widgets = get_option( ‘sidebars_widgets’ ); can be used. Which gives you an associative array containing a list of … Read more

Shortcode not working in widget

You have a conditional in your function that will skip (return) if the current “view” is not a single post. You also have an undefined variable $content – the following has the condition removed and undefined variable fixed (always, always have debugging on when building with WordPress): function newsletter_signup_shortcode( $atts ) { $post_type = get_post_type(); … Read more

Insert widgets into loop/custom query at every nth position

If you can get an index of your post then utilize % for CTA breaks. <?php // Your CTA Content $cta_array = array( “Some different content 1”, “Some different content ABC”, “Some different content XYZ”, ); $cta_inx = 0; // index $cta_len = count($cta_array); // max $cta_interval = 5; // breaks every x posts // … Read more

Repeated Output in Widget

Your widget markup is broken! Check this line $phone_link = ‘<a class=”contact-phone” href=”https://wordpress.stackexchange.com/questions/221244/tel:%s” itemprop=”telephone”>%s</span>’; Opening tag is <a> and closing tag is </span>. Correct it with $phone_link = ‘<a class=”contact-phone” href=”https://wordpress.stackexchange.com/questions/221244/tel:%s” itemprop=”telephone”>%s</a>’;

How can I delete a wordpress widget instance?

Widgets should only be manipulated by users, and in general they should not be deleted because there is no version control for them. Therefor I suggest you rethink first before reading further. Widgets are located in two places in the DB, the sidebar_widgets option is an array of sidebars, indexed by the sidebar id. Each … Read more

What does apply_filters() do exactly? [duplicate]

The $instance[‘title’] corresponds to the title enter in the widget. When a plugin or a widget as an apply_filters, the developper gently had a way to override the current value sets for the title. Now, imagine you setted a title (in the widget setting panel) but you want to change this value only if user … Read more

How to hide widget if current category has no posts assigned to it?

It might be you’re using the category on a custom post type, in that case category_count won’t include those. There’s another handy value on the $category-object however: $category->count. Try replacing this: $postcount = $thiscat->category_count; with this $postcount = $thiscat->count; The count attribute includes custom post types as well if the custom post type uses standard … Read more