Skip to navigation Skip to content
OTGS Knowledge Base
  • Login
  • Home
  • Add Code Snippets
  • Add Compatibility Snippet
  • Add Content
  • Add Content – Subscriber
  • Add Developer Resource
  • Add Quick Texts
  • Add Supporter Resource
  • Add Trainings
  • Add Webinars
  • All Courses
  • Contractor courses
  • Courses
  • Log In
  • Log Out
  • My Courses
  • New Request
  • Newly added resources
  • Privacy Policy and GDPR Compliance
  • Register
  • Reset Password
  • Set Password
  • Trainings

Assign different Layout depending on Post Status

This code allows you to assign a specific Layout to Posts in “draft” mode only. Read inline comments as well, the thread is interesting too.

function assign_layout_by_post_status( $id, $layout ){
 
        global $post;
 
        $preferred_layout = 5745; // my layout ID
 
        $control_layout = 0; //just set to 0 if you don't have any layout set for your post/product
 
        if( $id === $control_layout && $post->post_status === 'draft' && $post->post_type === 'product'){
            return $preferred_layout;
        }
        return $id;
    }
 
    add_filter('get_layout_id_for_render', 'assign_layout_by_post_status', 10, 2);

Support Thread Example

Let us know if this snippet is not working for you:

This snippet doesn’t work
Tags: front-end admin, update_post_meta

Post navigation

Previous post: Views Custom Query Filter – Check for custom Author cap.
Next post: Update Date Field with Today’s Date
0 0 votes
Article Rating
Subscribe
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
OnTheGoSystems - One team, one goal
0
0
Would love your thoughts, please comment.x
()
x
| Reply

Report Post

« »

 

Your Name:

Your Email:

Please tell us why do you think this post is inappropriate and shouldn't be there:


Cancel Report