【问题标题】:Php filter how to replace a bit of code with something else?php过滤器如何用其他东西替换一些代码?
【发布时间】:2015-04-21 21:04:13
【问题描述】:

大家好,我想学习在 wp 环境中使用 php 过滤器来执行此操作:filter on

<?php do_action( 'glow_credits' ); ?> 

要删除此演职员表并仅添加版权信息...我该怎么做?

<?php
/**
 * The template for displaying the footer.
 *
 * Contains the closing of the id=main div and all content after
 */
?>

    </div><!-- #main .site-main -->

    <?php get_sidebar(); ?>

    <footer id="colophon" class="site-footer" role="contentinfo">
        <div class="social-menu">
            <?php if ( has_nav_menu( 'social' ) ) {
                wp_nav_menu( array( 'theme_location' => 'social', 'container' => 'false', 'menu_class' => 'menu-social' ));
            } ?>
        </div><!-- .social-menu -->
        <div class="site-info">
            <?php do_action( 'glow_credits' ); ?>
            <a href="http://wordpress.org/" title="<?php esc_attr_e( 'A Semantic Personal Publishing Platform', 'glow' ); ?>" rel="generator"><?php printf( __( 'Proudly powered by %s', 'glow' ), 'WordPress' ); ?></a>.
            <?php printf( __( 'Theme: %1$s by %2$s.', 'glow' ), 'Snaps', '<a href="http://glow.com/" rel="designer">glow</a>' ); ?>
        </div><!-- .site-info -->
    </footer><!-- #colophon .site-footer -->
</div><!-- #page .hfeed .site -->

<?php wp_footer(); ?>

</body>
</html>

我知道该怎么做:

function test_new_action() {
  echo 'Howdy';
}
add_action('glow_credits','test_new_action');

但不替代...

【问题讨论】:

  • 您可以将多个函数挂接到一个动作中。您将需要删除具有功劳的原始文件才能正常工作。在您的主题文件中搜索 gloom_credits,然后您可以找到相关的功能。也可以注释掉调用该函数的 add_action 函数。

标签: php wordpress


【解决方案1】:

您可以使用 remove_filter() 取消挂钩现有函数 - 您只需要找出显示积分的函数的名称。

EG:如果函数被称为display_credits,那么你可以在你自己的钩子之前在你的函数中使用它:

remove_filter( 'glow_credits', 'display_credits' );

【讨论】:

    猜你喜欢
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-09
    • 1970-01-01
    • 2023-02-26
    • 2019-07-20
    • 1970-01-01
    相关资源
    最近更新 更多