Support » Plugins » Hacks » Automatically adding text to post titles?

  • Hi there,

    I want to automatically add the category of a post, to that post’s title. I am trying to emulate what they do at Mashable (see how they inserted [VIDEO] into the title in this article: http://mashable.com/2011/11/28/ups-package-not-delivered-scam/).

    Using the code below works, except for one issue. It adds the categories to all menus on the page, as well. See demo site for example result: http://rmthis.tfcsouthsider.com/

    So, my questions are:

    1. Does anyone see a way to get this code to work?
    2. Does anyone know a better way of automatically adding text to post titles?

    Your help is much appreciated. Thanks.

    function wpbeginner_cattitlerss($the_title) {
    $postcat = "";
    foreach((get_the_category()) as $cat) {
    $postcat .= ' ['.$cat->cat_name . ']';
    }
    $the_title = $the_title.$postcat;
    return $the_title;
    }
    add_filter('the_title', 'wpbeginner_cattitlerss');
  • The topic ‘Automatically adding text to post titles?’ is closed to new replies.