Skip to content

Instantly share code, notes, and snippets.

@campaignupgrade
Last active March 15, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campaignupgrade/933ac02cd2dc42711073fa91d82f3d22 to your computer and use it in GitHub Desktop.
Save campaignupgrade/933ac02cd2dc42711073fa91d82f3d22 to your computer and use it in GitHub Desktop.
Advanced Ads — Convert <div> to <aside>
<?php
/**
* Changes ad wrapper <div> element to <aside> element
* Does not work with cache-busting containers
*
* @param string $output ad output.
* @param object $ad Advanced_Ads_Ad object.
*
* @return string
*/
add_filter( 'advanced-ads-ad-output', function( $output, $ad ) {
$type = $ad->type;
if( $type != 'group' ) {
$output = preg_replace( '/^( <div )/', '<aside ', $output );
$output = preg_replace( '/(<\/div>)($|<script>)/', "</aside>\n$2", $output );
}
return $output;
}, 10, 2 );
@campaignupgrade
Copy link
Author

Updated to properly convert the closing tag in case the closing tag is immediately followed by a script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment