使用add_filter对wordpress进行非重复内容更改

时间:2012-09-21 16:12:25

标签: wordpress preg-replace

我想在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标记的位置?

1 个答案:

答案 0 :(得分:0)

我根本不使用数据库内容插入来支持CSS解决方案,ala this article

a[href $='.pdf'] { 
   padding-right: 64px;
   background: transparent url(domain.com/pdf-icon.jpg) no-repeat center right;
}