Advertisement
fauzanjeg

Change the WP Page Template to Elementor Canvas with Post ID.

Nov 2nd, 2023
1,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. /**
  2.  * Change the WP Page Template to Elementor Canvas with Post ID.
  3.  */
  4. function jkit_change_post_template() {
  5.     /**
  6.      * Please enter the Post ID you want to change its Page Template to Elementor Canvas.
  7.      */
  8.     $post_template_id = array( 11, 26 ); /** The Example is 11 and 26 */
  9.  
  10.     foreach ( $post_template_id as $id ) {
  11.         $page_template = get_post_meta( $id, '_wp_page_template', true );
  12.         $search_key    = 'elementor_';
  13.  
  14.         if ( strpos( $page_template, $search_key ) === false ) {
  15.             update_post_meta( $id, '_wp_page_template', 'elementor_canvas' );
  16.         }
  17.     }
  18. }
  19. add_action( 'init', 'jkit_change_post_template' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement