Widgets missing after update

I had to restore sidear_widgets in wp_options and any other entries with option_name including ‘widget’ from a database backup to resolve. Something must have go wrong during the update and all widget settings were lost.

Create onClick Event to Re-load a Widget

I think you something like this. HTML Add this in widget <a href=”https://wordpress.stackexchange.com/questions/254474/javascript:void(0)” id=”add_my_fav”>Add To Favourite<span id=”favCount”></span></a> Ajax Add this in template <?php $nonce = wp_create_nonce(‘addToFav’); ?> <script> jQuery(document).read(function(){ jQuery.ajax({ url: ‘http://example.com/wp-admin/admin-ajax.php’, data: {action:”add_to_favourite”, secret:”<?php echo $nonce; ?>”}, method: ‘POST’, success: function(res){ jQuery(‘#favCount’).html(res); } }) }) </script> PHP Add this in functions.php function addToFavourite(){ if(isset($_POST[‘secret’]) … Read more

How to insert custom widget in custom sidebar in theme activation?

but we have to change some little things if we want this when theme is activated.Changs maded done inside function awesome_register_sidebars.Add below code inside in your theme functions.php file: function awesome_register_sidebars() { $sidebars = array ( ‘a’ => ‘sidebar-footer-1’, ‘b’ => ‘sidebar- footer-2′,’c’=>’sidebar-footer-3’ ); foreach ($sidebars as $sidebar) { register_sidebar( array ( ‘name’ => $sidebar, … Read more

Adding widgets with Featured Image via the Customizer run hundreds of queries

The issue boils down to this bit of code in WP_Widget::display_callback(): $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { wp_suspend_cache_addition( true ); } This gets called right before WP_Widget_Recent_Posts::widget() and its purpose is to try as best as possible for back-compat to prevent widgets previewed in the Customizer from polluting the object … Read more

Widget for adding HTML markup to a page

If you want to do it the “WordPress-way”, you would create a custom post-type for books called “book” ( For this take a look at https://codex.wordpress.org/Function_Reference/register_post_type ). Then you would create an archive page for that post-type called “archive-book.php”. I hope this helps a little bit. If you need more help, let me know.

Custom Post Type Loop throws 500 error when used in widget

There are several problems in your provided code. $query -> while( have_posts() ) The WP_Query() return type is object. You are referring to a method that doesn’t exist. Instead, you should use the following: while( $query->have_posts() ) {…} wp_reset_postdata(); inside the conditional This function resets the post’s data, as it suggests. If you use it … Read more

Inject widgets from one sidebar into another with PHP

Here’s an (untested) idea where we inject the sidebar-inject sidebar before sidebar-target sidebar with help of the dynamic_sidebar_before hook : add_action( ‘dynamic_sidebar_before’, ‘wpse_inject_sidebar’, 10, 2 ); function wpse_inject_sidebar( $index, $has_widgets ) { // Only target front-end if( is_admin() ) return; // Only target ‘sidebar-target’ if( ‘sidebar-target’ !== $index ) return; // Make sure ‘sidebar-inject’ is … Read more

Recent Posts – Show all posts

Under settings you can control how many posts there are, you can’t set -1 which would be unlimited posts, but you can set a very high number: But What About just The Homepage? A lot of people get around this by putting a custom query in their homepage template, but those people are doubling the … Read more