Skip to content

Instantly share code, notes, and snippets.

@wpmark

wpmark/404.php Secret

Last active September 23, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmark/fd9e715e77f056a044ffe65b506db22f to your computer and use it in GitHub Desktop.
Save wpmark/fd9e715e77f056a044ffe65b506db22f to your computer and use it in GitHub Desktop.
Block editable 404 page
<?php
/**
* The template for displaying the 404 template.
*/
// get the themes header.php template.
get_header();
// get the 404 page.
$not_found_page = get_page_by_title( '404' );
// if we have a 404 page.
if ( null !== $not_found_page ) {
// get the blocks for the 404 page.
$blocks = parse_blocks( $not_found_page->post_content );
// create a var for the markup.
$content = '';
// loop through block.
foreach ( $blocks as $block ) {
// render this block into the content.
$content .= render_block( $block );
}
// output the 404 page content - the blocks!
echo $content;
} else {
?>
<p><?php esc_html_e( 'Sorry but the page you are looking for cannot be found.', 'textdomain' ); ?></p>
<?php
}
// get the themes footer.php template.
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment