Mayccoll
1/7/2016 - 8:56 PM

Add class to pdf files in content (class: pdf-file)

Add class to pdf files in content (class: pdf-file)

<?php
function THEME_add_pdf_class($content) {
  $patterns = '/<a(.*?)href=["|\'](.*?)([\.pdf|\.PDF])["|\']/';
  $replacements = '<a\1href="\2\3" class="pdf-file"';
  return preg_replace($patterns, $replacements, $content);
}
add_filter('the_content', 'THEME_add_pdf_class');
?>