Advanced Ads — Convert <div> to <aside>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to properly convert the closing tag in case the closing tag is immediately followed by a script.