我想在wordpress中自动为pdf链接添加pdf图标
function my_function($content) {
$search = '^.pdf">^';
$replace='.pdf"><img src="domain.com/pdf-icon.jpg" width="64" height="64" alt="pdf download"/>';
return preg_replace($search,$replace,$content);
}
add_filter('content_save_pre','my_function');
正常工作,但如果再次编辑帖子,则会添加另一张图片。
如何将其更改为不替换搜索.pdf
之后已经直接使用img标记的位置?
答案 0 :(得分:0)
我根本不使用数据库内容插入来支持CSS解决方案,ala this article:
a[href $='.pdf'] {
padding-right: 64px;
background: transparent url(domain.com/pdf-icon.jpg) no-repeat center right;
}