Insert ad 1/3rd the way down in content

Hi all,

Is there a supported manner to insert anything (ads in my case) at a certain point within the content, say 1/3rd from top, mid-way etc? I know it can be done within each .md file, but I am looking for the single.html template to handle it.

Also, it should take care of not inserting the ad in between the letters that form a word. It should always insert the ad in between words or sentences.


No, you cannot do this without a shortcode.

Shortcodes are definitely the best way to do this within individual content files.

Otherwise, you’d have to consider that “one-third” from the top of the Content is going to likely change for every page. You could do a word count, split the value, and insert an ad at the template level, but then you’d have broken sentences and a bad flow for readers. If this is about adding a client-side advertisement, you could also do this on the client in JavaScript by totaling the number of paragraphs, cutting it in half, rounding to the nearest whole number.checking to make sure the element that precedes the paragraph isn’t a heading, etc, but that feels ultra hackish. I’d recommend a shortcode for the highest degree of control…

1 Like