Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Convert Comment tag to link
- Description: Convert #tag to links in the comment_text area using a filter
- Author: Jan Dembowski
- */
- add_filter( 'comment_text', 'mh_commenttaglink' , 50 );
- 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 ) . '/tag/' . $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;
- }
Advertisement
Add Comment
Please, Sign In to add comment