0

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! :)

0

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.org/reference/functions/is_user_logged_in/

  • thanks so much for that. I'll stick that into my code ASAP! Just wondering as well – I'm looking to disable the ad in the excerpt for all users as well, because I can't stand the way it's showing up on my theme. How do I do that, either within this code block or otherwise? Thanks! – Jake Jun 16 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.