-
AuthorPosts
-
November 20, 2017 at 4:55 pm #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!
EnfoldedNovember 21, 2017 at 10:19 am #879606Hey 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,
RikardDecember 1, 2017 at 5:48 pm #883965Hi,
This is what I assumed. Wouldn’t it be just a function saying
open
after the 3rd flex_column, enter this javascript code
closeCould you make a first draft of how this function would work?
December 5, 2017 at 4:21 pm #885126Hi,
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,
IsmaelDecember 11, 2017 at 12:51 pm #887356Hey,
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.
December 12, 2017 at 2:53 pm #887945Hi,
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,
YigitDecember 14, 2017 at 10:12 pm #889123This reply has been marked as private.December 16, 2017 at 3:57 am #889461Hi,
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 -
AuthorPosts
- You must be logged in to reply to this topic.