Wordpress 在WP中过滤函数
我有一个儿童主题,我正在尝试过滤以下内容:Wordpress 在WP中过滤函数,wordpress,Wordpress,我有一个儿童主题,我正在尝试过滤以下内容: // add the function to the init hook add_action( 'init', 'options_typography_get_google_fonts' ); // add a font to the $google_fonts variable function options_typography_get_google_fonts() { // Google Font Defaults glo
// add the function to the init hook
add_action( 'init', 'options_typography_get_google_fonts' );
// add a font to the $google_fonts variable
function options_typography_get_google_fonts() {
// Google Font Defaults
global $google_faces;
$google_faces = array(
'Great Vibes, cursive' => '*Great Vibes'
);
return $google_faces;
}
最好的过滤方法是什么,这样我可以添加更多的谷歌字体?你的问题有点模糊,所以这里有一些选项: (1) 如果父主题检查
options\u typography\u get\u google\u font
函数是否存在(使用function\u exists
),则可以通过在子主题中重新声明该函数来覆盖该函数
(2) 如果父主题没有,您应该能够删除子主题中的操作:
remove_action('init','options_排版术\u get_google_字体')代码>
并基于刚刚删除的函数构建您自己的(类似但扩展的)函数
(3) 如果您正在构建子主题,并且希望用户能够过滤字体列表,则应返回可过滤数组:
return apply_filters('my_options_排版术_get_google_字体_filter',$google_faces)代码>