Skip to content

Instantly share code, notes, and snippets.

@khleomix
Last active February 16, 2022 20:33
Show Gist options
  • Save khleomix/57faeaae490ccc311620bc58a3d7f023 to your computer and use it in GitHub Desktop.
Save khleomix/57faeaae490ccc311620bc58a3d7f023 to your computer and use it in GitHub Desktop.
Block template function for the homepage.
<?php
/**
* Block template for Homepage
*
* @author JC Palmes
*/
function homepage_block_template() {
$current_id = isset( $_GET['post'] ) ? $_GET['post'] : '';
$current_post = isset( $_GET['post'] ) ? get_post($current_id) : '';
$current_slug = isset( $_GET['post'] ) ? $current_post->post_name : '';
if ( ! is_admin() || ! isset( $current_id ) || 'home' !== $current_slug ) {
// Only load template if slug is home.
return false;
}
$post_type_object = get_post_type_object( 'page' );
$post_type_object->template = array(
array( 'acf/hero-carousel' ),
array( 'acf/advertisement' ),
array(
'core/columns',
array(),
array(
array(
'core/column',
array(
'width' => 66.66,
),
),
array(
'core/column',
array(
'width' => 33.33,
),
),
),
),
);
$post_type_object->template_lock = 'all';
}
add_action( 'init', __NAMESPACE__ . '\homepage_block_template' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment