Last active
January 6, 2022 16:46
-
-
Save jslyonnais/49a7e5fce15cc38e90cb5cfdfc960300 to your computer and use it in GitHub Desktop.
WordPress + ACF - Register fields via PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'acf/init', 'register_allpage_fields' ); | |
function register_allpage_fields() { | |
$slug = "allpage"; | |
$fields = [ | |
[ | |
'key' => 'page_subtitle', | |
'label' => 'Subtitle', | |
'name' => 'page_subtitle', | |
'type' => 'text', | |
], | |
]; | |
acf_add_local_field_group([ | |
'key' => "group_$slug", | |
'title' => 'Options', | |
'position'=> 'acf_after_title', | |
'label_placement' => 'left', | |
'fields' => $fields, | |
'location' => [ | |
[ | |
[ | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => "page", | |
] | |
] | |
] | |
]); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Import Custom Fields | |
* | |
* @see Import any custom acf fields in `includes/custom-fields` folder | |
* @warning Required ACF Pro to be installed! | |
*/ | |
foreach (glob(get_template_directory() . '/includes/custom-fields/*.php') as $file) { | |
$filename = basename($file); | |
require_once locate_template('/includes/custom-fields/' . $filename); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment