• alexstrazsa

    (@alexstrazsa)


    Hi. I run a blog that sometimes posts content that doesn’t comply with AdSense content policies, so I decided to make a shortcode that I can add into specific posts which will remove the AdSense ads from that post.

    I’m using the GeneratePress theme, and the code works just fine for the Ad Unit above my posts, which is contained in its own and implemented via the GenerateHooks plugin. It does not, however, work for anything on the sidebar.

    This is the entirety of the plugin code:

    <?php
    /*
    Plugin Name: Hide Ads
    Plugin URI:
    Description:
    Version:
    Author:
    Author URI:
    License:
    License URI:
    */
    
    function remove_ads() {
    
    ?>
    <script>
      jQuery( ".fgkbsdkgjhbsgjds, .text-4, .text-11" ).remove();
    </script>
    <?php
    
    }
    add_shortcode( 'remove_ads', 'remove_ads');

    The first element there, “.fgkbsdkgjhbsgjds”, gets removed as it should, while the others aren’t affected at all.

    I suspect it has something to do with the sidebar widgets being “aside” classes instead of typical div classes, and I’m not sure how to remove something like that. I’ve tried this as well:

    jQuery( "aside" ).remove( ".text-4" );

    And it doesn’t change anything.

    Anyone have an idea?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Removing sidebar widgets with jQuery’ is closed to new replies.