Hiding Jetpack Ads from users who are signed in?

I'm just looking for some quick help if possible. I've just enabled Jetpack ads on my site, was hoping to use

I'm just looking for some quick help if possible. I've just enabled Jetpack ads on my site, was hoping to use ad-free viewing as a Patreon reward and found the posts on hooks and conditional tags. Since the option is missing from Jetpack's own settings, I'm assuming that pasting the hooks/tags into functions.php is the best way to do this, but I'm a bit of a novice when it comes to coding – especially PHP – and would just like to confirm that before I go making any modifications.

I'm guessing that I would use something along the lines of the following (and while I'm at it, disabling ads in the excerpt in general because they ruin my theme, haha):

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' );
}

But I'm not 100% certain. Can anyone confirm, deny, and/or edit the coding so that it's right? I'm also assuming that I can just paste it anywhere in the file, as has been the case with other database modifications I've seen?

Thanks so much in advance! :)

I'm just looking for some quick help if possible. I've just enabled Jetpack ads on my site, was hoping to use ad-free viewing as a Patreon reward and found the posts on hooks and conditional tags. Since the option is missing from Jetpack's own settings, I'm assuming that pasting the hooks/tags into functions.php is the best way to do this, but I'm a bit of a novice when it comes to coding – especially PHP – and would just like to confirm that before I go making any modifications.

I'm guessing that I would use something along the lines of the following (and while I'm at it, disabling ads in the excerpt in general because they ruin my theme, haha):

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' );
}

But I'm not 100% certain. Can anyone confirm, deny, and/or edit the coding so that it's right? I'm also assuming that I can just paste it anywhere in the file, as has been the case with other database modifications I've seen?

Thanks so much in advance! :)

Share Improve this question edited Jun 8, 2019 at 11:04 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jun 8, 2019 at 7:58 JakeJake 1
Add a comment  | 

1 Answer 1

Reset to default 1

Your code should be the good one. You just have to use is_user_logged_in() into a hook instead of calling it directly, and probably to early.

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' );

Using the template_redirect hook could be a good solution. You'll just have to paste this into your functions.php file. https://developer.wordpress/reference/functions/is_user_logged_in/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745398211a4625977.html

相关推荐

  • Hiding Jetpack Ads from users who are signed in?

    I'm just looking for some quick help if possible. I've just enabled Jetpack ads on my site, was hoping to use

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信