Support » Fixing WordPress » Custom link back to posts category

  • I was needing a link saying “back” that pointed to the category that the post was originally posted in. So I wrote this short plugin, I thought someone might use it.

    Plugin Name: Parent Category
    Plugin URI:
    Description: Adds a link to the parent category in the single.php template. To use, call the_parent_category_link(); where you want the link to appear.
    Author: Niels Hackius
    Version: 0.1
    Author URI:
    *based upon Parent Link (
    *by Denis de Bernardy(
    * Terms of use
    * ------------
    * Except where otherwise noted, this software is:
    * - Copyright 2005, Niels Hackius
    * - Licensed under the terms of the CC/GNU GPL
    * - Provided as is, with NO WARRANTY whatsoever
    *@param string $text optional specifies the string being displayed if used for direct output, defaults to "back"
    *@param boolean $selector optional if false the function only returns the url for use with php, if true it echos the string
    *to use just write:
    *<?php echo the the_parent_category_link() ?>
    function the_parent_category_link($text = "back", $selector = true)
    global $post;
    if ( !isset($post->post_category) ) {
    $url = get_settings('siteurl').'/index.php?cat='.$post->post_category;
    if(!$selector) {
    return $url;
    else {
    echo '<a href="'.$url.'">'.$text.'</a>';


  • The topic ‘Custom link back to posts category’ is closed to new replies.