当然您需要两件事—设置页面和自定义短代码处理程序。第一个有点过于宽泛,无法在这里详细讨论,但是this tutorial 应该有助于你开始。您还可以check out the codex, 如果你真的被卡住了,也可以在这里发回一个新问题。
现在来看短代码:
function wpse_203387_param_shortcode( $atts ) {
// [PARAM name="data"], $atts will be an array of name => data pairs
// [PARAM data], $atts will be a numeric array with one element, "data"
// In this case, we just always grab the first value/data
$name = array_shift( $atts );
switch ( strtolower( $name ) ) {
case \'youtubehome\' : // [PARAM youtubehome]
$data = get_option( \'theme_options\' ); // This is purely for example, use the data structure/names that match your settings API config
return $data[\'youtube_setting\'];
case \'anotherparam\' : // [PARAM anotherparam]
return \'something_else\';
}
}
add_shortcode( \'PARAM\', \'wpse_203387_param_shortcode\' );
Update: 要允许其他角色(功能)更新您的设置,请执行以下操作:
function wpse_203387_options_page_capability( $capability ) {
return \'edit_theme_options\';
}
add_filter( \'option_page_capability_my-theme-settings-name\', \'wpse_203387_options_page_capability\' );