Last active
March 15, 2019 04:19
-
-
Save campaignupgrade/933ac02cd2dc42711073fa91d82f3d22 to your computer and use it in GitHub Desktop.
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 ); |
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
This function will convert an Advanced Ads ad wrapper from a
<div>
tag to an<aside>
tag.The conditional is used to avoid creating two
<aside>
elements in case ad group ads are used to deliver ads. It probably won't hurt anything to have nested asides, but it's cleaner not to.We use this function to inform Google and other search engines that the ad text is not part of the post_content. This improves SEO and eliminates the chance of Google displaying the ad text in search result excerpts.