本文实例讲述了WordPress给文章图片主动增加链接的办法。分享给大家供大家参考。详细剖析如下:
咱们会看到有很多的网站咱们点击图片就会进入以后文件衔接了,上面我来给应用wordpress博客的同窗也来引见此种办法,图片主动链接到文章,增加题目和ALT属性.
间接将上面的代码增加到主题的 functions.php 文件即可:
function auto_post_link($content) {
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i', "<a href="".get_permalink()."" title="".$post->post_title."" ><img src="$2" alt="".$post->post_title."" /></a>", $content);
return $content;
}
add_filter ('the_content', 'auto_post_link',0);<a href="wordpress-view-history.html" title="WordPress 增加文章阅读历史性能" >
<img src="201303521.png" alt="WordPress 增加文章阅读历史性能" />
</a>还能够再增加一个性能,将文章标签作为要害词,将文章内的要害词主动加上链接,无利于SEO,他人复制的时分,就会留下链接了,在下面的函数里持续增加一段代码即可:
function auto_post_link($content) {
global $post;
$content = preg_replace('/<s*imgs+[^>]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>/i', "<a href="".get_permalink()."" title="".$post->post_title."" ><img src="$2" alt="".$post->post_title."" /></a>", $content);
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$content = preg_replace(''(?!((<.*?)|(<a.*?)))('. $keyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))'s','<a href="'.$link.'" title="'.$keyword.'">'.$keyword.'</a>',$content,2);//最多交换2个反复的词,防止适度SEO
}
}
return $content;
}
add_filter ('the_content', 'auto_post_link',0);
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《WordPress给文章图片自动添加链接的方法》的一些看法。更多内容请查看本栏目更多内容!
处理方法: 办法一: 修正文件“/wp-includes/pluggable.php”中的wp_set_auth_cookie函数。搜寻...
尚未装置WordPress 在初始配置WordPress之前,将wp-config.php中的$table_prefix值(默许为wp_)修正为所需求...
复制代码代码如下: <?php //Put this in functions.php function get_primary_image($id, $size){ ...
明天,特带来了5个实例技巧,至多能够协助冤家们在缩小wordpress博客的负荷上起到一点点作用吧,上面和网友...
调用最新文章: 复制代码代码如下: <ul> <?php $post_query = new WP_Query(‘showposts=10′); ...
函数引见 update_option()用于更新数据表中存在的选项值。该函数可取代add_option,但不迭add_option灵敏。...