首页 > 解决方案 > 排除标记链接

问题描述

我已尽力创建标签插件,但我在这里存货。我的目标是我想从 html 标签中排除标签链接等。我想了很多主意,但似乎从来没有奏效。它应该跳过这些 html 部分。请我需要帮助请。

$replace_times=3;
add_action('admin_menu','tag2link_setting_options');
add_filter('the_content','tag2link');
init_tag2link();
$tags;
function init_tag2link(){
    add_option('tag2link_times');
    add_option('tag2link_use');
}
function getPostTags(){
global $post_ID;
}
function tag2Link($s){
    global $id;
    global $replace_times;
    global $wp_rewrite;
    $te=get_option('tag2link_use');
    if($te=='te')   $useTe=true;
    else $useTe=false;
    $us=get_option('tag2link_times');
    $replace_times=intval($us);
    if($replace_times==0) $replace_times=3;
    /*
        Get tag permalink structure
    */
    //$structure=$this->get_tag_permastruct();
    $ss=$wp_rewrite->get_tag_permastruct();
    $structure="";
    if($ss==false) {
        $structure=get_option('siteurl').'/?tag=%tag%';
    }else $structure=get_option('siteurl').$ss;
    /*
        Get post tags
    */
    $tags=wp_get_post_tags($id);
    $p=$s;
    if($tags==null) return $p;
    /*
        Start replace
    */
    $count=count($tags);
    usort($tags,cmp);
    $temp=$structure;
    foreach($tags as $value){

        if($useTe){
            $pattern='/(?<=[^a-zA-Z])'.$value->name.'(?!.*<\/a>)/';
            $replace='<a href="http://localhost/wordpress/tag/'.$value->slug.'">'.$value->name.'</a>';
            $p=preg_replace($pattern,$replace,$p,$replace_times);
        }
        else{
                $structure=str_replace('%tag%',$value->slug,$temp);
            if($ss==false){
                $pattern='/(?<=[^a-zA-Z])'.$value->name.'(?!.*<\/a>)/';
                //$pattern='/(?<!\/\?)(?<!\w)'.$value->name.'(?!\w)(?!(\s|\w)*<\/a>)/';
            }else{
                //$pattern='/(?<!\/)(?<!\w)'.$value->name.'(?!\w)(?!(\s|\w)*<\/a>)/';
                $pattern='/(?<=[^a-zA-Z])'.$value->name.'(?!.*<\/a>)/';
            }
            $tag_permalink = get_tag_link($value->term_id);
            $replace='<a href="'. $tag_permalink .'">'.$value->name.'</a>';
            $p=preg_replace($pattern,$replace,$p,$replace_times);
        }
     }      
    return $p;
}
function cmp($a,$b){
    return strlen($a->name)-strlen($b->name);
}
function tag2link_setting_options(){
        add_options_page('Tag to Links', 'Tag to Links', 5, 'automatic-tag-link/options.php');

查看代码我不希望标签链接出现在所有 h2、h2、h1、h4、html 文本中。包括,标签等。请我真的需要这个请。我已经尽力了,但没有出路。

标签: wordpress

解决方案


嗨,希望这可以帮助你。这段代码使用缓冲区。

尝试通过替换您的值来检查您的代码

循环遍历具有不同值的缓冲区内容


推荐阅读