Skip to content

Instantly share code, notes, and snippets.

@benlumley
Created March 20, 2019 09:52
Show Gist options
  • Save benlumley/2a299f5279ae7f3b235808946ce911e8 to your computer and use it in GitHub Desktop.
Save benlumley/2a299f5279ae7f3b235808946ce911e8 to your computer and use it in GitHub Desktop.
Add banners into content
jQuery(function ($) {
var $banners = $('aside .ba');
if ($banners.length) {
// find all the headings in post body - we want to put the banners in after headers
var $headings = $('#post_full .span9 > *').filter(':header');
// work out how often to put one in
var inc = Math.floor($headings.length / $banners.length);
var current = inc+1;
// loop over the banners, insert after headings using the above increment
$banners.each(function () {
$this = $(this);
jQuery($headings.get(current)).after($this);
current = current + inc;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment