• Resolved andersonkoh

    (@andersonkoh)


    Hi, I’m trying to display my category description on the category archive page. However, I face some issues with using return at the end of my PHP code, but echo does the work.

    $category_description = get_queried_object()->category_description;
    
    return $category_description;
    

    But adding this in Theme File Editor will work with return.

    • This topic was modified 2 years, 1 month ago by andersonkoh.
    • This topic was modified 2 years, 1 month ago by andersonkoh.
    • This topic was modified 2 years, 1 month ago by andersonkoh.
    • This topic was modified 2 years, 1 month ago by andersonkoh.
    • This topic was modified 2 years, 1 month ago by andersonkoh.
    • This topic was modified 2 years, 1 month ago by andersonkoh.
Viewing 1 replies (of 1 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @andersonkoh,

    That seems to be working as intended. The code in that snippet will be executed “as is” in the location you choose. Return will not output anything but echo will. Usually, you would use return at the end of a function, for example, and then echo the value returned by the function if you want it to output in the frontend.

    Adding it in the Theme File Editor depends where you add it, if you are adding the code inside a function that then gets called and echoed in a template file, it will work.

Viewing 1 replies (of 1 total)
  • The topic ‘return does not work but echo does’ is closed to new replies.