Internal blog links
Monday 21st December 2009 by admin
When blogging, internal blog links – that is links between your posts – are important. Being able to link related content to each other helps readers and search engines alike therefore great for SEO – but creating all those links can be time consuming and often confusing. Here is a simple WordPress function I wrote that uses the WordPress add-action() hook function to create automatic links for category names in the content of posts.
To implement copy the function and past into your WordPress function file. That way every time you mention a category name in the text of a post a link will be created to the category archive, therefore related posts.
Hope this is helpful
-
function tag_post_display($content) {
-
-
global $wpdb;
-
-
$content_new = $content;
-
-
$tag_result = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."term_taxonomy
-
LEFT JOIN ".$wpdb->prefix."terms ON ".$wpdb->prefix."terms.term_id = ".$wpdb->prefix."term_taxonomy.term_id
-
WHERE ".$wpdb->prefix."term_taxonomy.taxonomy=’category’");
-
-
foreach ($tag_result as $tag_result) :
-
-
$content_new = str_replace($tag_result->name,‘<a href="’.get_option(‘home’).‘/category/’.$tag_result->slug.‘">’.$tag_result->name.‘</a>’,$content_new);
-
-
endforeach;
-
-
return $content_new;
-
-
}
-
-
add_action(‘the_content’, ‘tag_post_display’, 9);
-
Obviously this WordPress function could be extended in numbers of ways nor just category names but also keywords, tags and much more.
Popularity: 3% [?]



0
COMMENTS