0

My home page uses ACF ("settings home") fields. These fields position the items in the footer. The problem is that they don't display on other sites. How to display fields from the home page on all subpages? So that you do not have to enter the same data on each subpage

To display in footer.php I'm using:

<?php the_field('contact_form_title'); ?>

2 Answers 2

1

ACF's the_field() and get_field() accept several parameters, one of which is a post ID. So, you just need to get the ID of the page the field is on, like this:

<?php
$frontpage_id = get_option( 'page_on_front' );
the_field('contact_form_title', $frontpage_id); 

// For pages other than home
$page = get_page_by_path('some-page-slug');
the_field('contact_form_title', $page->ID);
?>
1

If you have the Pro version of the plugin, you might be better to use an ACF Options Page.

More info: https://www.advancedcustomfields.com/resources/options-page/

You'll need to enable it in your theme by adding something like this to your functions.php file.

if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_page(array(
        'page_title'    => 'Theme General Settings',
        'menu_title'    => 'Theme Settings',
        'menu_slug'     => 'theme-general-settings',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));
}

Then you can pop this into your footer;

<?php the_field( 'field_name', 'option' ); ?>

However you should be weary of the the fact that this will be another database query, so if you're worried about speed then it might be better to hard code the content into footer.php

At this moment in time, Options pages are only in the Pro version of the plugin I believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.