Support

Account

Home Forums Backend Issues (wp-admin) Can't get value from options page in functions.php Reply To: Can't get value from options page in functions.php

  • Hi there @krtmedia

    Initially you will want to create the Options Page. You can use this code resource, or this plugin.

    Here’s example code for an Options Page that can be added to functions.php or a custom plugin:

    <?php
    if( function_exists('acf_add_options_page') ) {
     
    	$option_page = acf_add_options_page(array(
    		'page_title' 	=> 'Global Settings',
    		'menu_title' 	=> 'Global Settings',
    		'menu_slug' 	=> 'my-global-settings',
    		'capability' 	=> 'edit_posts',
    		'redirect' 	=> false
    	));
     
    }
    ?>

    Then, you create a Fieldset within ACF for that Options page.

    So… you create a URL field called “pricelist” for example.

    Then… you visit the Options Page and give your “pricelist” field a value, and click “Update”.

    Then… to reference it with code..

    <?php
    // to 'echo' it
    the_field('pricelist', 'option');
    
    // to return the value, and perhaps assign it to a variable for later use
    $price_list = get_field('pricelist', 'option');
    ?>

    Is that helpful, or do you need further assistance?