WordPress
给文章开头或结尾添加自定义内容(三种代码)使用
WordPress
创作的时候,有时需要给所有文章开头或结尾添加自定义内容,下面的方法即可帮助到你。如图所示:
实现的三种代码
将下列代码添加到当前使用主题的functions
.php
文件,并修改为自己想呈现的相应内容。
No
.1
//在所有文章底部添加自定义内容 1 模板
function
add_after_post_content
($content
) {
if
(!is_feed
() && !is_home
() && is_singular
() && is_main_query
()) {
$content
.= '本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台,如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。';
}
return
$content
;
}
add_filter
('the_content
', 'add_after_post_content
');
全选
复制
No
.2
//在所有文章底部添加自定义内容 2 模板
function
zm_content_insert
( $return
= 0 ) {// 插入的内容
$str
.= ;
$str
.= ;
$str
.= https
://www
.huizhanii
.com
/;
$str
.= ;
if
($return
) { return
$str
; } else
{ echo
$str
; }
}
function
zm_content_filter
($content
) {
if
(!is_feed
() && !is_home
() && is_singular
() && is_main_query
()) {
//$content
.= zm_content_insert
(0);// 0 在正文上面
$content
.= zm_content_insert
(1);//1 在正文下面
}
return
$content
;
}
add_filter
('the_content
','zm_content_filter
');
全选
复制
No
.3
//在所有文章底部添加自定义内容 3 模板
add_filter
('the_content
', 'fanly_copyright
');
function
fanly_copyright
($content
) {
if
(is_single
() or
is_feed
()) {
$content
.= ;
$content
.= .get_bloginfo
('url
').'" target
="_blank
">'.get_bloginfo
('name
').;
$content
.= .get_the_title
().'" href
="'.get_permalink
().'" target
="_blank
">'.get_permalink
().;
return
$content
;
}
}
转载请注明:汇站网 » WordPress给文章开头或结尾添加自定义内容(三种代码)