Skip to content

Instantly share code, notes, and snippets.

@Nikschavan
Created March 12, 2018 13:58
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Nikschavan/3ee6b62efb2f7dc1c5ccd34faed0e954 to your computer and use it in GitHub Desktop.
Save Nikschavan/3ee6b62efb2f7dc1c5ccd34faed0e954 to your computer and use it in GitHub Desktop.
Set of filter overrides to set up default layout for a specific post type.
<?php // don't copy this line in your code
/**
* Setup default Astra settings for a single post layout for specific post type.
*
* This Removes header, Footer, Post title, Featured image, Post navigation.
* Sets content layout to "Fullwidth Stretched" and sidear layout to `no-siebar`
*/
function your_prefix_disale_header_footer() {
// bail early if the current post type if not the one we want to customize.
if ( 'your-post-type' !== get_post_type() && is_singular() ) {
return;
}
// Disable Header, Above/below header, Sticky header.
remove_action( 'astra_header', 'astra_header_markup' );
// Disable Footer widgets, Footer bar.
remove_action( 'astra_footer', 'astra_footer_markup' );
// Set the page page layout to 'no-sidebar'.
add_filter( 'astra_page_layout', 'your_prefix_change_page_layout' );
// Set the content layout to 'page-builde' i.e. Fullwidth Stretched.
add_filter( 'astra_get_content_layout', 'your_prefix_astra_content_layout' );
// Disable Post title.
add_filter( 'astra_the_title_enabled', '__return_false' );
// Disale Featured image.
add_filter( 'astra_featured_image_enabled', '__return_false' );
// Disale post navigation links.
add_filter( 'astra_single_post_navigation_enabled', '__return_false' );
// Disable Comments.
// This filter is from WordPress filter to disable comments.
add_filter( 'comments_open', '__return_false' );
}
add_action( 'wp', 'your_prefix_disale_header_footer' );
/**
* Returns string for no sidear layout.
*
* @return 'String' String to set the page layout to 'no-sidebar'.
*/
function your_prefix_change_page_layout () {
return 'no-sidebar';
}
/**
* String to set Content layout to Fullwidth Stretched.
*
* @return 'String' String 'page-builder' as the content layout.
*/
function your_prefix_astra_content_layout() {
return 'page-builder';
}
@atomicjeep
Copy link

thanks this was very helpful

@jodamo5
Copy link

jodamo5 commented Aug 12, 2021

A comment to help others who might find this code: I was expecting this would affect the admin view when creating a new post with that custom post type. I though the checkboxes for which items would be disabled (e.g. title, feature image, etc) would be affected in the admin view, but this code doesn't do that. It instead just affects the frontend view, overriding whatever is set on the post in the admin view.

If you want to do that, you need to use these alternative filters instead:
https://wpastra.com/docs/disable-all-meta-settings-of-page-post-by-default/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment