Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atazmin/3a11eb71aab4925546916ee1de24d904 to your computer and use it in GitHub Desktop.
Save atazmin/3a11eb71aab4925546916ee1de24d904 to your computer and use it in GitHub Desktop.

YouTube Video: https://youtu.be/ejova7SU_h0

Options page

Using ACF field

Block type: Text Block (WYSIWYG field)

Text:
[acf field="NAME-OF-ACF-FIELD" post_id="options"]

Image (Return Format: Image URL) and alt text:
<img src="[acf field='NAME-OF-ACF-FIELD' post_id='options']" alt="[acf field='NAME-OF-ACF-FIELD' post_id='options']" />

Using Shortcode

Block type: Text Block (WYSIWYG field)

[location_start_your_application_group]

functions.php

if ( function_exists('acf_add_options_page') ) {
	acf_add_options_page(array(
		'page_title' 	=> 'Sitewide Settings',
		'menu_title'	=> 'Sitewide Settings',
		'menu_slug' 	=> 'sitewide-general-settings',
		'capability'	=> 'edit_posts',
		'redirect'		=> false
	));

	acf_add_options_sub_page(array(
		'page_title' 	=> 'Sitewide Head Settings',
		'menu_title'	=> 'Head',
		'parent_slug'	=> 'sitewide-general-settings',
	));

	acf_add_options_sub_page(array(
		'page_title' 	=> 'Sitewide Header Settings',
		'menu_title'	=> 'Header',
		'parent_slug'	=> 'sitewide-general-settings',
	));

	acf_add_options_sub_page(array(
		'page_title' 	=> 'Sitewide Body Settings',
		'menu_title'	=> 'Body',
		'parent_slug'	=> 'sitewide-general-settings',
	));

	acf_add_options_sub_page(array(
		'page_title' 	=> 'Sitewide Footer Settings',
		'menu_title'	=> 'Footer',
		'parent_slug'	=> 'sitewide-general-settings',
	));
}

add_filter('acf/settings/save_json', function ( $path = '' ) {
	$path = get_stylesheet_directory() . '/acf-json';
	return $path;
});

add_filter('acf/settings/load_json', function ( $paths = array()) {
	$paths = array( get_stylesheet_directory() . '/acf-json' );
	return $paths;
});

add_shortcode('location_start_your_application_group', 'get_start_your_application_group');

function get_start_your_application_group() {

	$start_your_application_group = '';

	$start_your_application_group .= '<section class="start-your-application">';
	 if ( have_rows( 'start_your_application_group', 'option' ) ) : 
		 while ( have_rows( 'start_your_application_group', 'option' ) ) : the_row(); 
		   $heading = get_sub_field( 'heading' );
			 $content = get_sub_field( 'content' );

			 if ( $heading !== '' ) {
					$start_your_application_group .= '<h3 class="start-your-application__heading">' . $heading . '</h3>';
			 }
			 if ( $content !== '' ) {
				$start_your_application_group .= '<div class="start-your-application__content">' . $content . '</div>';
			 }

			 $image = get_sub_field( 'image' );
			 if ( $image ) { 
				$start_your_application_group .= '<div class="start-your-application__image-container"><img class="start-your-application__image" src="' . esc_url($image['url']) .'" alt="' . $image['alt'] . '" /></div>';
			} 
		endwhile;
	endif;

	$start_your_application_group .= '</section>';
	
	return $start_your_application_group;
}

acf-json/group_5eaccec06b17b.json

{
    "key": "group_5eaccec06b17b",
    "title": "Body",
    "fields": [
        {
            "key": "field_5eaccedde21f0",
            "label": "Locations",
            "name": "",
            "type": "tab",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "placement": "top",
            "endpoint": 0
        },
        {
            "key": "field_5eace7604faac",
            "label": "Start Your Application Group",
            "name": "start_your_application_group",
            "type": "group",
            "instructions": "",
            "required": 0,
            "conditional_logic": 0,
            "wrapper": {
                "width": "",
                "class": "",
                "id": ""
            },
            "layout": "block",
            "sub_fields": [
                {
                    "key": "field_5eace77a4faad",
                    "label": "Heading",
                    "name": "heading",
                    "type": "text",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "prepend": "",
                    "append": "",
                    "maxlength": ""
                },
                {
                    "key": "field_5eace7854faae",
                    "label": "Content",
                    "name": "content",
                    "type": "wysiwyg",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "tabs": "all",
                    "toolbar": "full",
                    "media_upload": 1,
                    "default_value": "",
                    "delay": 0
                },
                {
                    "key": "field_5eace7cd79fe3",
                    "label": "Image",
                    "name": "image",
                    "type": "image",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "return_format": "array",
                    "preview_size": "medium",
                    "library": "all",
                    "min_width": "",
                    "min_height": "",
                    "min_size": "",
                    "max_width": "",
                    "max_height": "",
                    "max_size": "",
                    "mime_types": ""
                }
            ]
        }
    ],
    "location": [
        [
            {
                "param": "options_page",
                "operator": "==",
                "value": "acf-options-body"
            }
        ]
    ],
    "menu_order": 0,
    "position": "normal",
    "style": "default",
    "label_placement": "top",
    "instruction_placement": "label",
    "hide_on_screen": "",
    "active": 1,
    "description": "",
    "modified": 1588471676
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment