WP Royal Team


Important: before adding the code, please make a backup. You can use this plugin – https://wordpress.org/plugins/updraftplus/ or make sure to test it on a development or staging environment before running it on a live website.

To set Right Sidebar for all pages you will need to insert the following code at the end the functions.php file. Then you need to visit your website home page and refresh it once (this will update all pages with the custom value). After that you can remove the code from functions.php file.

$args = array(
    'post_type' => 'page',
    'post_status' => 'publish',
    'posts_per_page' => -1
$all_pages = new WP_Query( $args );
if ( $all_pages->have_posts() ) {
    while ( $all_pages->have_posts() ) {
        update_post_meta(get_the_ID(), 'show_page_sidebar', 'rsidebar');

Kind Regards

  • This reply was modified 2 months ago by Nick.