首页 文章

如何从wordpress子主题过滤可插入功能

提问于
浏览
0

我需要在特定的wordpress函数中添加一个过滤器,该函数在一个可插入函数主题函数f包含的文件中定义 .

的functions.php:

if (!function_exists('nectar_colors_css_output')) {
    function nectar_colors_css_output(){
        include('css/colors.php');
    }
}

colors.php:

<?php 
function nectar_colors() {
    // not relevant what happens here, but I have 
    // to call another function before this one is called!
}
?>

我使用子主题,当我尝试从子主题的functions.php中过滤此函数时,没有任何反应 . 这是因为父主题的可插入函数将被调用 after 从子主题调用过滤器 .

我在子主题的functions.php中的过滤函数是

function filter_function() {
  // some custom actions...
}
add_filter('nectar_colors', 'filter_function');

如何让这个过滤器工作?

1 回答

  • 0

    你到底想要过滤什么?你可能会误解这些概念 .

    拿你提供的例子 . 父项在创建函数之前检查函数是否存在 . 所以基本上,如果你在孩子的主题中定义它,父母就会知道它在那里并且不会创建默认主题 .

    #themename-child
    
    function nectar_colors_css_output(){
        error_log("It worked!");
    }
    

相关问题