Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Last active December 9, 2023 23:28
Show Gist options
  • Save danielcharrua/d3a41b41ead2a103046e51b7fd78d43c to your computer and use it in GitHub Desktop.
Save danielcharrua/d3a41b41ead2a103046e51b7fd78d43c to your computer and use it in GitHub Desktop.
Add Gutenberg content to blog page on Astra
//Please add this to your functions.php
/**
* This snippet adds Blog page Gutenberg content before the posts grid on Astra theme if you are using a static homepage.
*
* First create a page for displaying posts, for example "Blog", add any Gutenberg block.
* Then on settings assign a static frontpage and the created "Blog" page to blog posts.
*
* You can now add any block content to the "Blog" page and it will be shown before the posts loop.
*/
if ( ! function_exists( 'astra_blog_page_title_and_content' ) ) {
function astra_blog_page_title_and_content() {
if ( is_home() ) { ?>
<section class="ast-archive-description">
<?php
$page_for_posts_id = get_option('page_for_posts');
echo get_post_field( 'post_content', $page_for_posts_id );
?>
</section>
<?php }
}
add_action( 'astra_primary_content_top', 'astra_blog_page_title_and_content' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment