Skip to content

Instantly share code, notes, and snippets.

@yehudah
Created April 13, 2015 13:17
Show Gist options
  • Select an option

  • Save yehudah/29bbe757aac355af0464 to your computer and use it in GitHub Desktop.

Select an option

Save yehudah/29bbe757aac355af0464 to your computer and use it in GitHub Desktop.
Hyperlink words matching your wordpress site tags, in your posts content.
<?php
/*
Plugin Name: Post Words To Tags.
Description: Hyperlink words matching your site tags in your posts content.
Author: Yehuda Hassine
Author URI: http://wpdevops.co.il
Version: 1.0
License: GPL2
*/
/*
Copyright (C) 2015 Yehuda Hassine
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_filter( 'content_save_pre', 'mark_tags', 10, 1 );
function mark_tags( $content ) {
$tags = get_tags();
foreach ($tags as $tag) {
if ( preg_match( "/{$tag->name}/", $content ) ) {
$tag_link = get_tag_link( $tag->term_id );
$url = "<a href='{$tag_link}' title='{$tag->name}' class='{$tag->slug}'>{$tag->name}</a>";
$content = str_replace( $tag->name, $url, $content );
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment