We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14336
    • 4 Posts
    Is it possible to setup a snippet or chunk of code *to run adsense code for example* that will run automatically inside of a post’s content?

    I would like to have an advertisement appear after the second paragraph of every entry, and have one appear at the end of all the content as well.

    I also want to actually insert a small section of "Related Posts" within the content that will move the content to the side and have the related posts displayed.

    I basically intend on having a lot of code inserted within the content and I’d like to have this done automatically. Actually it is essential.

    So if anyone could help, point me in the right direction, as I’m enjoying this CMS, and I’m sure it is capable of doing this. I would appreciate it a lot smiley
      • 3749
      • 24,544 Posts
      If you don’t mind putting them in by hand, you can create two snippets that each contain the appropriate Google Adsense code.

      Then you can put [!GoogleSnippetOne!] after the second paragraph and [!GoogleSnippetTwo!] at the end of the content.

      If you want this done automatically, I think you’d have to either:

      1) Write a custom snippet that parsed the content and plugged in the Adsense code, or

      2) Create two Template Variables, one to hold the first two paragraphs, and one to hold the rest of the content. Then put those TVs and the adsense code into the page template - like so:

      TV1
      Google code
      TV2
      Google code

      Maybe someone else can think of an easier way.

      Bob
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You could use a plugin, but it would be a little tricky to code, unless you specifically put comment tags or some other marker where you wanted to insert the Adsense code.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org