Enable Right Sidebar in WordPress all Post for Astra theme

Enable Right Sidebar in WordPress all Post for Astra theme
516 Views

Easy way to enable right sidebar in all wordpress post for astra theme add following code in your current themes functions.php file.

<?php
add_action( 'init','cxc_sidebar_add_func' );
function cxc_sidebar_add_func(){
   $args = array(
      'post_type'=> 'post',
      'orderby'    => 'ID',
      'post_status' => 'publish',
      'order'    => 'DESC',
      'posts_per_page' => -1
   );
   $result = new WP_Query( $args );
   if ( $result-> have_posts() ) : ?>
      <?php while ( $result->have_posts() ) : $result->the_post(); 
         update_post_meta( get_the_ID(), 'site-sidebar-layout', 'right-sidebar' ); 
      endwhile; 
   endif;
   wp_reset_postdata(); 
}
?>

Was this article helpful?
YesNo

Leave a comment

Your email address will not be published. Required fields are marked *