Skip to content

Instantly share code, notes, and snippets.

@kmaroff
Created February 29, 2020 17:22
Show Gist options
  • Select an option

  • Save kmaroff/e855333166fac22b7139c246171471f0 to your computer and use it in GitHub Desktop.

Select an option

Save kmaroff/e855333166fac22b7139c246171471f0 to your computer and use it in GitHub Desktop.
//Добавляем нужный атрибут к ссылкам ведущих к изображениям в статьях. В примере используем fancybox
add_filter('the_content', 'addfancybox');
function addfancybox($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 data-fancybox title="'.$post->post_title.'"$6>';
$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