I am trying to add some text to the end of every post belonging to a specific category. I am using the following code -

<div class="repair-tool">
    $catarray = get_the_category( $post->ID );
    foreach ($catarray as $cat) {
        $catid = $cat->term_id;
        if ($catid == 1234) {
          echo 'text';
    } ?>

This is working successfully but div class I am using is being shown in every post of the website instead. Please somebody help me out.

1 Answer 1


It seems you are pointing to this div class "repair-tool". Correct?

If yes then you can modify your code like the below:

if( in_category( 1234, $post->ID ) ){
    echo '<div class="repair-tool">text</div>';
  • Thank you so very much, Tiwari ji. Worked like a charm.
    – SK21
    Nov 9, 2022 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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