wordpress外链 WordPress外链图片灯箱效果
如何让WordPress自动对外链添加"nofollow"标签
这个实现起来还是挺简单的,你可以使用以下代码试试:
双桥网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联公司2013年开创至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司。
//给外部链接加上nofollow标签
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('/a(.*?)href="(.*?)"(.*?)/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false strpos($val,home_url())===false !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"$val\" ",$content);
}
}
}
return $content;
}
不过现在大部分WordPress站点都是直接将外链变成内链来跳转的,具体可以参考本站分享的《实测WordPress外链转内链跳转地址为Base64加密地址》这篇文章。
wordpress写文章过程中添加创建的相册,如何给相册里的每张图片单独添加外链?
图片信息实际仍存储在posts表中,post_type为attachment
后台相册编辑界面里没有专门的栏目用于填写外链地址,不过可以通过其他字段实现啊
如下图,在alt text字段里填上该图片的外链
接着,需要参考wp-includes/media.php文件里的gallery_shortcode函数来重构gallery的输出
在functions.php中添加代码如下:
add_filter('post_gallery', 'my_post_gallery', 10, 3);
function my_post_gallery( $html = '', $attr, $instance ) {
$post = get_post();
$html5 = current_theme_supports( 'html5', 'gallery' );
$atts = shortcode_atts( array(
'order' = 'ASC',
'orderby' = 'menu_order ID',
'id' = $post ? $post-ID : 0,
'itemtag' = $html5 ? 'figure' : 'dl',
'icontag' = $html5 ? 'div' : 'dt',
'captiontag' = $html5 ? 'figcaption' : 'dd',
'columns' = 3,
'size' = 'thumbnail',
'include' = '',
'exclude' = '',
'link' = 'none'
), $attr, 'gallery' );
$id = intval( $atts['id'] );
if ( ! empty( $atts['include'] ) ) {
$_attachments = get_posts( array( 'include' = $atts['include'], 'post_status' = 'inherit', 'post_type' = 'attachment', 'post_mime_type' = 'image', 'order' = $atts['order'], 'orderby' = $atts['orderby'] ) );
$attachments = array();
foreach ( $_attachments as $key = $val ) {
$attachments[$val-ID] = $_attachments[$key];
}
} elseif ( ! empty( $atts['exclude'] ) ) {
$attachments = get_children( array( 'post_parent' = $id, 'exclude' = $atts['exclude'], 'post_status' = 'inherit', 'post_type' = 'attachment', 'post_mime_type' = 'image', 'order' = $atts['order'], 'orderby' = $atts['orderby'] ) );
} else {
$attachments = get_children( array( 'post_parent' = $id, 'post_status' = 'inherit', 'post_type' = 'attachment', 'post_mime_type' = 'image', 'order' = $atts['order'], 'orderby' = $atts['orderby'] ) );
}
if ( empty( $attachments ) ) {
return '';
}
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id = $attachment ) {
$output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
}
return $output;
}
$itemtag = tag_escape( $atts['itemtag'] );
$captiontag = tag_escape( $atts['captiontag'] );
$icontag = tag_escape( $atts['icontag'] );
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) ) {
$itemtag = 'dl';
}
if ( ! isset( $valid_tags[ $captiontag ] ) ) {
$captiontag = 'dd';
}
if ( ! isset( $valid_tags[ $icontag ] ) ) {
$icontag = 'dt';
}
$columns = intval( $atts['columns'] );
$itemwidth = $columns 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";
$gallery_style = '';
/**
* Filters whether to print default gallery styles.
*
* @since 3.1.0
*
* @param bool $print Whether to print default gallery styles.
* Defaults to false if the theme supports HTML5 galleries.
* Otherwise, defaults to true.
*/
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
$gallery_style = "
style type='text/css'
#{$selector} {
margin: auto;
}
#{$selector} .gallery-item {
float: {$float};
margin-top: 10px;
text-align: center;
width: {$itemwidth}%;
}
#{$selector} img {
border: 2px solid #cfcfcf;
}
#{$selector} .gallery-caption {
margin-left: 0;
}
/* see gallery_shortcode() in wp-includes/media.php */
/style\n\t\t";
}
$size_class = sanitize_html_class( $atts['size'] );
$gallery_div = "div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'";
/**
* Filters the default gallery shortcode CSS styles.
*
* @since 2.5.0
*
* @param string $gallery_style Default CSS styles and opening HTML div container
* for the gallery shortcode output.
*/
$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
$i = 0;
foreach ( $attachments as $id = $attachment ) {
$attr = ( trim( $attachment-post_excerpt ) ) ? array( 'aria-describedby' = "$selector-$id" ) : '';
if ( ! empty( $atts['link'] ) 'file' === $atts['link'] ) {
$image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr );
} elseif ( ! empty( $atts['link'] ) 'none' === $atts['link'] ) {
$attr['alt'] = get_the_title($post-ID);
$image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr );
$custom_link = trim( strip_tags( get_post_meta( $id, '_wp_attachment_image_alt', true ) ) );
$image_output = sprintf( 'a href="%s" title="%s"%sa',
$custom_link,
$attr['alt'],
$image_output
);
} else {
$image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr );
}
$image_meta = wp_get_attachment_metadata( $id );
$orientation = '';
if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
$orientation = ( $image_meta['height'] $image_meta['width'] ) ? 'portrait' : 'landscape';
}
$output .= "{$itemtag} class='gallery-item'";
$output .= "
{$icontag} class='gallery-icon {$orientation}'
$image_output
/{$icontag}";
if ( $captiontag trim($attachment-post_excerpt) ) {
$output .= "
{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'
" . wptexturize($attachment-post_excerpt) . "
/{$captiontag}";
}
$output .= "/{$itemtag}";
if ( ! $html5 $columns 0 ++$i % $columns == 0 ) {
$output .= 'br style="clear: both" /';
}
}
if ( ! $html5 $columns 0 $i % $columns !== 0 ) {
$output .= "
br style='clear: both' /";
}
$output .= "
/div\n";
return $output;
}
最后的效果:
请问你是如何实现wordpress特色图片支持外链的呢
楼下鬼扯,由于安全方面的考虑,wordpress里是根本不支持外链图片作为特色图片的
真要实现这功能的话必须得自己改动下代码了
首先在需要显示特色图像的地方(比如首页,内容页)添加以下代码:
?php
if ( $values = get_post_custom_values("thumb") ) { ?
a href="?php the_permalink() ?" title="?php the_title(); ?"img class="thumb" src="?php $values = get_post_custom_values("thumb"); echo $values[0]; ?" alt="?php the_title(); ?" //a
?php } else { ?
a href="?php the_permalink() ?" title="?php the_title(); ?"img class="thumb" src="/images/thumb.jpg" alt="?php the_title(); ?" //a
?php } ?
PS:上面代码的css选择器class="thumb"需要在css中自定义样式。
接下来使用方法是:第一次的时候在自定义栏目里输入新栏目名称为thumb,然后在值里输入缩略图地址,绝对路径或者相对路径都可以。不输入的话是不会有任何内容出来的
方法2:安装一个插件:“featured image from url”
如何在wordpress文章里批量插入图片外链?
可以直接切换到文本格式,电脑端使用网页编辑器或者文本编辑器批量编辑好连接图片格式,然后复制粘贴即可
当前标题:wordpress外链 WordPress外链图片灯箱效果
标题URL:http://scyanting.com/article/dogepsp.html