Problem: I have Layout A assigned as the Layout for the Pages post type. However, under certain circumstances I would like to preselect Layout B when a Page is being created in wp-admin.
Solution: There's not a filter available to manipulate the selected Layout here, but you could use the WordPress "save_post" hook to override the User's Layout selection when the post is saved.
function override_default_layout( $post_id ) { if( get_post_type($post_id) == 'page' && wp_get_post_parent_id( $post_id ) == 1234 ) { // this page is a child of the page with ID 1234 so we need to update the _layouts_template postmeta update_post_meta( $post_id, '_layouts_template', 'template-slug'); } } add_action( 'save_post', 'override_default_layout', 100 );
Change '1234' to match the numeric ID of the Photos page, and change 'template-slug' to match the slug of the correct Layout. This way, no matter what is selected, the correct Layout will be applied.
Relevant Documentation: https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 7 years, 1 month ago.
Assisted by: Christian Cox.