Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #879219

    Hi,

    I’d like to add a code in functions.php – that on every page in my website, after the 3rd .flex_column, an AdSense code should be added. This is better than adding shortcodes since I’d have update a lot of pages then.

    Thank you for the help!
    Enfolded

    #879606

    Hey Enfolded,

    If you are going to use the same layout for your pages, then maybe it would be easier to save and load a template? I think a function like would be pretty complicated to write unfortunately.

    Best regards,
    Rikard

    #883965

    Hi,

    This is what I assumed. Wouldn’t it be just a function saying

    open
    after the 3rd flex_column, enter this javascript code
    close

    Could you make a first draft of how this function would work?

    #885126

    Hi,

    You can start with the following script. Add it in the functions.php file.

    // custom script
    add_action( 'wp_footer', 'ava_custom_script' );
    function ava_custom_script() {
    ?>
    <script type="text/javascript">
    (function($) {
    	function a() {
    		$('.flex_column:nth-child(3n)').each(function() {
    			 $(this).append('adsense code');
    			 // some other code here
    		});
    	}
    
    	$(document).ready(function() {
    		a();
    	});
    })(jQuery);
    </script>
    <?php
    }

    Best regards,
    Ismael

    #887356

    Hey,
    Thanks for the code!
    I inserted the code in functions.php but it shows only debugs a code in the very bottom of my page as:

     
    '; }); } $(document).ready(function() { a(); }); })(jQuery);
    

    The code I made (after insetting Google Adsense looks like this)

    // custom script
    add_action( 'wp_footer', 'ava_custom_script' );
    function ava_custom_script() {
    ?>
    <script type="text/javascript">
    (function($) {
    	function a() {
    		$('.flex_column:nth-child(3n)').each(function() {
    			 $(this).append('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- Ads -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-123456789123"
         data-ad-slot="123456789"
         data-ad-format="auto"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>');
    			 // some other code here
    		});
    	}
    
    	$(document).ready(function() {
    		a();
    	});
    })(jQuery);
    </script>
    <?php
    }

    Would you please help edit the above code so it works? :)

    • This reply was modified 6 years, 11 months ago by Enfolded.
    #887945

    Hi,

    Can you please post WP admin logins here privately so we can look into it? We may need FTP logins in case something goes wrong so please post them as well if you do not mind :)

    Best regards,
    Yigit

    #889123
    This reply has been marked as private.
    #889461

    Hi,

    I tried to create a script to dynamically append the adsense on every 3rd columns but it’s creating an adsense script error. I’m sorry but I don’t think this is possible. You can’t manipulate the adsense code dynamically. You have to add it directly in the page.

    Another user created a adsense shortcode.

    // https://kriesi.at/support/topic/container-problems-using-short-codes-with-enfold-editor/#post-887689

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.