How To Update Sidebars In Bulk

How To Update Sidebars In Bulk


Sometimes, especially when you have a lot of posts of a certain post type, instead of changing sidebars manually per post, it would be preferrable to update the sidebars in bulk. One option to achive this is using the Custom Field Bulk Editor plugin.

But it can also be done with a short custom script, which we will explain below. We will be using get_posts() to query the posts. For more information about customizing the get_posts() call, you can check the WordPress Codex here:

To update sidebars in bulk, follow the steps below

Step 1 - In your WP backend navigate to Appearance > Editor.

Step 2 - Find the Theme Functions file called functions.php. You can either use the one in child or parent theme.

Step 3 - Enter a new line after the first <?php.

Step 4 - If you want to update sidebar 1, copy snippet 1 from below, otherwise snippet 2 to your functions.php.

Step 5 - In the code below, replace #your-post-type with the post type you want to bulk update sidebars for. E.g.: 'post', 'page', 'avada_portfolio', 'product', or the slug of your custom post type.

Step 6 - In the code below, replace #your-sidebar-name with the actual name of the sidebar you want your posts to show. E.g 'Blog Sidebar'. Use '0' to update to the default value (which will pull from Theme Options then). Set to '', to remove sidebars.

Step 7 - Click save and refresh your website.

Step 8 - Navigate back to the editor and remove the code you inserted into functions.php.

Code to update sidebar 1 to “#your-sidebar-name” for all posts of post type “#your-post-type”:

Copy to Clipboard

Code to update sidebar 2 to “#your-sidebar-name” for all posts of post type “#your-post-type”:

Copy to Clipboard

Recent Posts

Recent Tweets

For privacy reasons Twitter needs your permission to be loaded. For more details, please see our Privacy Policy.
I Accept