All of my categories has a custom single post title type, such: "How to TITLE Free" and then the article.

I want to get another title if category is News. So i won't have "How To TITLE Free" for single posts titles, but instead I will have "TITLE" only.

How can I do this? Thank you.

  • how is that custom single post title type done? is that 'How to ... Free' added to the normal title via code?
    – Michael
    Mar 12, 2020 at 16:44
  • yes, exactly. i am posting an article, and the title will automatically add "how to .... free" in it. Mar 14, 2020 at 15:10
  • please post the code that automatically adds the 'how to ... free' to the title. you will need to add a condition to that code, that stops it from adding it if the post is in the 'News' category...
    – Michael
    Mar 14, 2020 at 18:53
  • check the code: pastebin.com/7gCH5KTj (row 2) Mar 15, 2020 at 14:44

2 Answers 2


change this one line in your code:

<h1 class="article-title entry-title">How To <?php the_title(); ?> Free</h1>


<h1 class="article-title entry-title"><?php if( in_category( array('news') ) ) { the_title(); } else { ?> How To <?php the_title(); ?> Free<?php } ?></h1>


  • Thank you, Michael. But seems to not work. I got this error: "There has been a critical error on your website. Learn more about debugging in WordPress" when trying to access any post. Mar 16, 2020 at 21:51
  • apologies, there was an error in the code; I corrected my answer.
    – Michael
    Mar 16, 2020 at 22:20
  • wow! it really works. Thanks a lot, Michael. Mar 17, 2020 at 9:27

use get_the_category() to get category of posts. Compare it with your required category like:

$category = get_the_category();
if($category[0]->name == 'news') { 
   echo the_title();
} else {
   echo "title";

Hope this helps


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.