Skip to content

Commit

Permalink
提供正文内容链接加跳转功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Lvshujun0918 committed Mar 25, 2024
1 parent 0933de2 commit 3b00b99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions inc/fun/opt.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,33 @@ function pk_go_link($url, $name = '')
return $url;
}

//开启了内页链接跳转
if (pk_is_checked('link_go_page')) {
/**
* 内页跳转链接
*
* @param string $content 修改前的内容
* @return string 修改后的内容
* @author lvshujun
* @date 2024-03-19
*/
function pk_content_addlink($content) {
//匹配链接
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if ($matches) {
foreach ($matches[2] as $val) {
if (strpos($val,'://') !== false
&& pk_is_cur_site($val) === false
&& !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)) {
$content = str_replace('href="'.$val.'"', 'href="'.pk_go_link($val).'"', $content);
}
}
}
return $content;
}
add_filter('the_content', 'pk_content_addlink');
}

//检测链接是否属于本站
function pk_is_cur_site($url)
{
Expand Down
6 changes: 6 additions & 0 deletions inc/setting/options/OptionBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function get_fields(): array
'type' => 'switch',
'sdt' => 'false',
],
[
'id' => 'link_go_page',
'label' => __('正文内容链接加跳转', PUOCK),
'type' => 'switch',
'sdt' => 'false',
],
[
'id' => 'use_post_menu',
'label' => __('正文内容侧边目录菜单生成', PUOCK),
Expand Down

0 comments on commit 3b00b99

Please sign in to comment.