对登录的用户隐藏Jetpack广告?

时间:2019-06-08 作者:Jake

如果可能的话,我只是想寻求一些快速的帮助。我刚刚在我的网站上启用了Jetpack广告,希望使用无广告观看作为Patreon奖励,并在hooksconditional tags. 由于Jetpack自己的设置中缺少该选项,我假设将挂钩/标签粘贴到函数中。php是实现这一点的最佳方法,但在编码方面,尤其是php方面,我还是一个新手,在进行任何修改之前,我想确认一下这一点。

我猜我会按照下面的思路使用一些东西(虽然我在做,但通常会禁用摘录中的广告,因为它们破坏了我的主题,哈哈):

if ( is_user_logged_in(true) {
add_filter( \'wordads_excerpt_disable\', \'__return_true\' );
add_filter( \'wordads_content_disable\', \'__return_true\' );
add_filter( \'wordads_inpost_disable\', \'__return_true\' );
add_filter( \'wordads_header_disable\', \'__return_true\' );
}
但我不是百分之百肯定。是否有人可以确认、拒绝和/或编辑编码以确保其正确?我还假设我可以将其粘贴到文件中的任何位置,就像我看到的其他数据库修改一样?

提前非常感谢!:)

1 个回复
SO网友:Elex

你的代码应该是好的。你只需要使用is_user_logged_in() 而不是直接调用它,很可能是提前调用。

function wp_se_339916() {
    if ( is_user_logged_in() {
        add_filter( \'wordads_excerpt_disable\', \'__return_true\' );
        add_filter( \'wordads_content_disable\', \'__return_true\' );
        add_filter( \'wordads_inpost_disable\', \'__return_true\' );
        add_filter( \'wordads_header_disable\', \'__return_true\' );
    }
}
add_action( \'template_redirect\', \'wp_se_339916\' );
使用template_redirect 胡克可能是一个很好的解决方案。您只需将此粘贴到functions.php 文件https://developer.wordpress.org/reference/functions/is_user_logged_in/

相关推荐