How to Get ACF Value from Main Blog Page?

If you have ACF fields on your main blog page and you are troubled with displaying the field, this tutorial will help you to sort it out. Let’s do start

Let’s, we have an ACF field for the page banner title. Basically, we get and display the field like the below codes

// Getting Value
$page_title = get_field( 'page-title' ); // Here page-title is ACF field name
// Displaying Name
<?php if( $page_title ): ?>
<h2><?php echo esc_html($page_title); ?></h2>
<?php endif; ?>

The above code works well for all pages except the Blog page. For the Blog title the code looks like this:

// Getting value
$page_title = get_field( 'page-title', get_option( 'page_for_posts' ) );

// Displaying value
<?php if( $page_title ): ?>
    <h2><?php echo esc_html($page_title); ?></h2>
<?php endif; ?>

Hope this tutorial is helpful for you.

For more about ACF you may follow the link here:

Thank you!

Leave a Reply

Your email address will not be published.