Using ACF to display data on all pages

I have installed Advanced Custom Fielts, and I have created custom fields such as email, phone etc. I put those in my footer.php, and the data is displayed only on the homepage.
Can I use ACF to create global variables?
My rule for that custom field is 'If Post Type is equal to post';

I get that data in footer.php like this

$phone_number = get_field('phone_number');

and Im displaying it like

<?php echo $phone_number; ?>

So basically when Im on my homepage, it is displayed correctly, when I go to other page(which has that same footer), data is not displayed.
What can I do to display it on all pages?

3 Answers
3

You Need to use ACF Options Page plugin as well.

This Plugin has been deleted from the repository. Now you can use the function without the plugin.

The options page feature provides a set of functions to add extra admin pages and all data saved on an options page is global.

Sea the plugin overview

After installing plugin you have to add the following to your functions.php

if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_page();
    
}

and the “Options” label will be visible in your admin area.

then you just need to create acf fields with the rule like 'If Options Page is equal to Options'

Finally to display the field:

echo get_field('phone_number', 'option');

Leave a Comment