<?php
/*
Plugin Name: Convert Comment tag to link
*/
add_filter( \'comment_text\', \'mh_commenttaglink\' , 5000 );
function mh_commenttaglink( $text ) {
// RegEx to find #tag, #hyphen-tag with letters and numbers
$mh_regex = "/\\ #[a-zA-Z0-9-]+/";
// Use that RegEx and populate the hits into an array
preg_match_all( $mh_regex , $text , $mh_matches );
// If there\'s any hits then loop though those and replace those hits with a link
for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
{
$mh_old = $mh_matches[0][$mh_count];
$mh_old_lesshash = str_replace( \'#\',\'\',$mh_old);
$mh_new = str_replace( $mh_old , \'<a href="\' . get_bloginfo( url ) . \'/search/%23\' . $mh_old_lesshash . \'" /rel="tag">\' . $mh_old . \'</a>\' , $mh_matches[0][$mh_count] );
$text = str_replace( $mh_old , $mh_new , $text );
}
// Return any substitutions
return $text;
}
知道怎么回事吗?当在注释部分中的单词之前键入哈希符号时,链接将按如下方式推出-
blablahblah/#word
代替blahblahblah/#word
我真的看不出我在这里错过了什么。我们将不胜感激。