Created
December 13, 2018 12:58
-
-
Save amorkovin/1e542b20eff69cd4c6eb7784bd166701 to your computer and use it in GitHub Desktop.
Закрыть подписи к изображениям от индексации в WordPress
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
add_filter( 'the_content', 'morkovin_add_noindex_img_cap', 1000 ); | |
function morkovin_add_noindex_img_cap( $content ) { | |
$pattern = "/<p class=\"wp-caption-text\">([^<]+)<\/p>/i"; | |
$replacement = "<!--noindex--><p class=\"wp-caption-text\">$1</p><!--/noindex-->"; | |
$content = preg_replace($pattern, $replacement, $content); | |
$pattern = "/<div class=\"wp-caption-text\">([^<]+)<\/div>/i"; | |
$replacement = "<!--noindex--><div class=\"wp-caption-text\">$1</div><!--/noindex-->"; | |
$content = preg_replace($pattern, $replacement, $content); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment