Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to show author name only if the post is in a specific category?

Yes, that is the line you need to edit, and you need to check and see if the current post is within your specified category. So you could replace that line with this code and it should do the trick:

if(in_category(90)) {
    $author = mom_option('post_meta-author') == 1 ? '<span class="author vcard" itemprop="author" itemscope itemtype="https://schema.org/Person">'.__('Posted By:', 'theme').' <span class="fn" itemprop="name"><a href="'.$author_link.'">'.get_the_author().'</a></span></span>': '';
} else {
    $author="";
}

If that doesn’t work, either you have the wrong category ID, or the post object isn’t getting set correctly at this point (i.e. you aren’t in the loop).

Also note: you don’t have to use the category ID, you can use the slug or name if you want it to be more readable code.

Related Posts:

  1. Checklist of selected categories
  2. Is it possible to disable certain user roles from creating tags?
  3. How to set up sub-categories for author pages?
  4. Custom query with category exclusion and post-meta “whitelist”
  5. How to make a relationship between books and authors?
  6. Root level category, tag, author and archive pages to work
  7. How to have a static category/author page?
  8. Automatically assign posts by author to a specific category
  9. Search by word, category, tag, author
  10. How to group the loop posts in a particular by author?
  11. How to control template resolution if both Author and Category filter in place?
  12. Hide post meta data on a specific category
  13. Display posts separated by Category in Author’s page
  14. How to display singular form of category name?
  15. Restrict author to create subcategory in a selected category
  16. Add /category/ to an author archive page
  17. get_post_meta not working on category.php
  18. Hidde certain category from post meta
  19. How to conditionally hide author name on Single.php if category is “news”, otherwise if category is something else display author name?
  20. Is there a way to only show Custom Meta Data on single posts from certain catagories
  21. Author Page – List of categories plus number of posts in that category
  22. How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?
  23. Post by category+author not working!
  24. Display Related Posts by “Category” “by Author”
  25. Get Meta Keys of Custom Categories
  26. Custom meta boxes ID prefix showing on first category but not others
  27. what file I need to create to work date archive links?
  28. Assign author to category and not only posts
  29. Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
  30. Assignt automatically two categories by author
  31. How to fetch common posts from two feeds?
  32. Remove “Category:” from Post meta
  33. Displaying data from custom fields on a specific category page
  34. Please tell how to stop the category from showing up on posts
  35. how to get postmeta info based on multiple categories?
  36. Assign a category to all articles
  37. How do you add Author and date Published on Category Pages?
  38. how to Specifies an author / editor to edit one category only?
  39. How can I hide the category term for posts with none set?
  40. Hide all posts by an author
  41. Archives and category of authors
  42. How can i hide the authors box from a specific set of categories and post types?
  43. How to display posts by author in a separate page, other than author.php?
  44. Limit authors on specific catogories
  45. How to create an automatic MultiColoumn MegaMenu with Categories WordPress
  46. Is There a Difference Between Taxonomies and Categories?
  47. List all subcategories from category
  48. How To Find Out WordPress Category Table in MYSQL?
  49. Add custom field to Category
  50. Get Category ID inside Category template
  51. Only one category per post
  52. WordPress Multisite – global categories
  53. Get the children of the parent category
  54. Get posts from sites in Multisite?
  55. WP REST API: filter by category 1 AND category 2
  56. How To Get Parent Category Slug of Current Post
  57. Display All Products by Category with WooCommerce
  58. What is the difference between a “tag” and a “category”?
  59. Is there an easy way to make a meta box have the tabs like the Categories meta box has?
  60. How to check if I’m on the last page of posts?
  61. Display posts from the same category using next/previous post link
  62. How would I get a taxonomy/category list inside a Gutenberg block?
  63. Can I set a default featured image for a category?
  64. Check if a post is in any child category of a parent category
  65. How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
  66. Force category choice before creating new post?
  67. Gutenberg editor add a custom category as wrapper for custom blocks
  68. WooCommerce: List All Categories
  69. How to get category and archive title?
  70. Get category ID from category slug (not working)
  71. How do I remove “Uncategorized” from posts with more than 1 category?
  72. How to add category to: ‘wp-admin/post-new.php’?
  73. Get rid of WordPress category, tag and author archives?
  74. Individual rss feed entry length for categories?
  75. How can I create a category landing page followed by pages of posts?
  76. Remove parent category from permalink? Basically only have the child category?
  77. Custom permalink structure leads to be 404 on pagination
  78. Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
  79. Posts URL structure like site.com/category/the-post-title
  80. Can’t custom taxonomies have same terms (slugs) as categories?
  81. How to get permalinks with category base working with sub-categories
  82. How to remove the term “category” from category pagination?
  83. Using wp_category_checklist in a widget
  84. WP 3.9 TinyMCE no longer loads on category description editor
  85. On the category page, get the category object
  86. Get only the top level categories using get_categories() without foreach loop
  87. Get all categories and posts in those categories
  88. How to add featured image for category (without a plugin)?
  89. How to create a custom sort for WordPress categories
  90. How to display non-hierarchical taxonomy as terms with checkboxes?
  91. Category archive by year with permalink support /category/YYYY
  92. Best Way to Redirect Category to Page and Hide Category
  93. get_terms vs. get_categories: does it matter?
  94. What is a good robots.txt?
  95. Allow users to create their own feed from selected categories?
  96. Hook when category is added to post
  97. get_categories for custom post type with a specific custom taxonomy attached
  98. Add a URL prefix to permalinks of one category of posts only
  99. How do you add categories to custom post types in WordPress?
  100. Create a category list page
Categories categories Tags author, categories, post-meta
Custom page template for category taxonomy
How can I create a gallery showing Ken Burns effect, when mouse hovers over images? [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress