我相信其他人可以指出其他方法,但我只是在这里提出我认为最快的方法:使用Advanced Custom Fields PRO 以及他们的option pages functionality. 从他们的文档中:
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\',
));
}
然后,当您需要选项页面中的任何值时,只需使用如下内容:
$option_x = get_field(\'option_x\', \'options\');