在子主题中重写父主题函数?如何去做


Override Parent Theme Function in Child Theme? How?

我想改变这个函数的输出

function ph_mailchimp($action){
    $msg = get_theme_mod('pic_mailchimp', 'text');
    $output = '
    <div class="newsletter-box well">
      <p>' . $msg  . '</p>
      <form accept-charset="UTF-8" action="'.$action.'" class="new_subscriber" data-remote="true" id="mc-embedded-subscribe-form" method="post">
        <div style="display:none">
          <input name="utf8" type="hidden" value="">
        </div>
        <input class="inputfield" id="mce-EMAIL" name="EMAIL" placeholder="Your email" type="email">
        <input name="subscribe" type="submit" value="Subscribe">
      </form>
    </div>';
    return $output;
}

基本上,我想在我的子主题的functions.php文件中添加一个代码来覆盖上面函数中的输出。

有人能帮忙吗?谢谢。

可以,如果您有适当的设置。从PECL安装APD,或者从PECL安装runkit。如果你有runkit,这应该可以:

runkit_function_remove ( "ph_mailchimp" );
function ph_mailchimp() {
    echo "Foobar";//do stuff here
}