Sunday, January 8, 2023
HomeWordPress DevelopmentIs there a method to change the default put up template choice...

Is there a method to change the default put up template choice for a selected class?


After we add the brand new put up,the default template is chosen.
I wish to change the default chosen template to my customized template mechanically earlier than publishing or saving the put up.
Here is an instance:

Template Choices by default:

Default Template (mechanically chosen)
My Template 1
My Template 2

Is there a WordPress method to change to:

Default Template
My Template 1 (mechanically chosen)
My Template 2

I used to be capable of make it for all posts however needed for particular class solely

 operate default_temp() {
 international $put up;
 if ( 'put up' == $post->post_type 
  //&& is_category('8')
  && 0 != rely( get_page_templates( $put up ) ) 
  && get_option( 'page_for_posts' ) != $post->ID // Not the web page 
  for itemizing posts
  && '' == $post->page_template // Solely when page_template isn't 
  set
  ) {
    $post->page_template = "single-post-game.php";
   }
}
add_action('add_meta_boxes', 'default_temp', 1);

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments