I have a channel that stores ads (HTML ads I created and the Google Adsense Code block), and displays either my html or Google's JS to allow a random ad on each page load. I want to insert that channel entry code from my Ad Channel in the middle of every post from my Article Channel – say after the 6th paragraph.

I could split the post entry field into two fields and do something like: " {postHalfOne}{adCodeSnippet}{postHalfTwo} ", but that doesn't allow for changing the breakpoint in the future.

Basic HTML can be inserted after a certain number of paragraphs via javascript, but it is my understanding that javascript can not be used to pass ExpressionEngine code. My test code works to insert HTML (fiddle), just not with my exp:channel:entries code. Can I change my code to work with EE or is JS the wrong solution here?

2 Answers 2


Another option would to go with a Blocks or Content Elements approach, where your content is actually a list of content building blocks. Then you can have any combination: text-ad-text, text-ad-ad-text, text-ad-text-ad-text, text-somethingelse-text-ad-text, etc.

The value of that is that editors can just click on an "Ad" button, instead of needing to remember that the syntax is {advertisement} to include an advertisement. And you can have a little bit more flexibility (especially if you need multiple ads).

Disclosure: I wrote Blocks.


A couple of options here.

One is to wrap your entry content in the Allow EE Code plugin, and then include your ad code via an embed wherever you ant it to appear in your entry, e.g.


The other option is to use something like NSM Transplant, with which you can do something like this.

Include this as a "token" for your ad inside your content:


Then in your template:


  {exp:channel:entries channel="ads" limit="1" dynamic="no"}
    {exp:nsm_transplant:content id="advertisement"}
      {!-- Whatever you need to include here for your ad to render --}

  {exp:channel:entries channel="articles" limit="1"}
    {!-- {advertisement} inside of {content} will be parsed and replaced with the content inside of {exp:nsm_transplant:content} above --}

  • Also consider Hop Inject (devot-ee.com/add-ons/hop-inject) as an alternative to NSM Transplant, doing much the same job but at a third of the price.
    – RickL
    Commented Mar 10, 2015 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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