Showing posts with label create custom option in theme. Show all posts
Showing posts with label create custom option in theme. Show all posts

Wednesday, April 19, 2023

Create footer option with acf in wordpress admin panel

Hello
Today I explain how to create footer option in admin side with ACF (Advance Custom Fields) Plugin. Its easy to use.

1 : Open your theme's functions.php file and insert this code

//acf option page
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
    ));
    
    acf_add_options_sub_page(array(
        'page_title'    => 'Theme Header Settings',
        'menu_title'    => 'Header',
        'parent_slug'   => 'theme-general-settings',
    ));
    
    acf_add_options_sub_page(array(
        'page_title'    => 'Theme Footer Settings',
        'menu_title'    => 'Footer',
        'parent_slug'   => 'theme-general-settings',
    ));
    
}
//end option page

Now save it and refresh your admin panel. You can see this type of option.


2: Go to Custom fields option and create footer option like this: Set option like this:



save it. And create custom fields like copyright text. slug is : copyright_text
3:  Go to Dashboard-> Theme Settings -> Footer
You will find this 

save it
4: this is for footer. So open your footer.php file and put code like this.

 <?php if(!empty(get_field('copyright_text','option'))) :?>
         <p><?php echo the_field('copyright_text','option'); ?></p>
 <?php endif; ?>