Title: PHP in shortcode doesn&#8217;t display on widgets
Last modified: January 26, 2018

---

# PHP in shortcode doesn’t display on widgets

 *  Resolved [fran330](https://wordpress.org/support/users/fran330/)
 * (@fran330)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/php-in-shortcode-doesnt-display-on-widgets/)
 * Hi,
    The shortcode containing PHP works on pages/posts but when I write `[category-
   name]` in a text widget or in a Custom HTML widget, it displays nothing, since
   version 3.0.2
 * If I do the same with a shortcode containing HTML (no php), it works fine though.
 * I am sure my php code is valid because it used to work.
    Here it is:
 *     ```
       $current_cat_id = the_category_ID(false);
       echo '<span>' . get_cat_name($current_cat_id) . '</span>';
       ```
   
 * “Shrotcode” and “PHP code” are ticked.
 * I hope you can help,
    Thanks in advance, Fran
    -  This topic was modified 8 years, 3 months ago by [fran330](https://wordpress.org/support/users/fran330/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-in-shortcode-doesnt-display-on-widgets%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [davdebcom](https://wordpress.org/support/users/davdebcom/)
 * (@davdebcom)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/php-in-shortcode-doesnt-display-on-widgets/#post-9916470)
 * Hi Fran
 * When reviewing your support request, I noticed that the_category_ID() is deprecated:
   
   [https://developer.wordpress.org/reference/functions/the_category_id/](https://developer.wordpress.org/reference/functions/the_category_id/)
 * Tested this on 2.5.4 and 3.0.0, it only worked when the shortcode was added in
   the Text widget and when the shortcode was shown on a post page. It does not 
   work in other widgets or when not on a page/post in either version.
 * Shortcodes in Text widget seem to be supported since WordPress 4.9. You might
   have been using another plugin or code snippet to allow shortcodes in widgets
   before that. Please check that, maybe they no longer work or cause conflicts 
   because it is now in core.
 * > [Widget Improvements in WordPress 4.9](https://make.wordpress.org/core/2017/10/24/widget-improvements-in-wordpress-4-9/)
 * It doesn’t work on other pages then pages/posts because the function needs the
   post/page ID to get the category ID.
 * You can download that old version from this page, install it and confirm if it
   does or does not work for you:
    [https://wordpress.org/plugins/post-snippets/advanced/](https://wordpress.org/plugins/post-snippets/advanced/)
 * Kind regards
    David
 *  Thread Starter [fran330](https://wordpress.org/support/users/fran330/)
 * (@fran330)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/php-in-shortcode-doesnt-display-on-widgets/#post-9921644)
 * OMG! I am so stupid and so sorry…
    I am building a new website and as I was testing
   stuff, I totally forgot that the concerned code was meant to appear on a post
   page only (and disply its own category). Of course, that’s the purpose of it…
   In fact, it works prefectly!
 * Thank you for pointing out the deprecated code. I’ll look into that.
 * Again, I am sorry for having taken your attention for nothing..
    Thank you for
   your response though 🙂 Fran
 *  [davdebcom](https://wordpress.org/support/users/davdebcom/)
 * (@davdebcom)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/php-in-shortcode-doesnt-display-on-widgets/#post-9926341)
 * Hi Fran
 * Not a problem!
 * If you like Post Snippets and the support, please feel free to let us know in
   the reviews:
    [https://wordpress.org/support/plugin/post-snippets/reviews/#new-post](https://wordpress.org/support/plugin/post-snippets/reviews/#new-post)
 * Kind reagrds
    David

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP in shortcode doesn’t display on widgets’ is closed to new replies.

 * ![](https://ps.w.org/post-snippets/assets/icon-128x128.gif?rev=2545587)
 * [Post Snippets - Custom WordPress Code Snippets Customizer](https://wordpress.org/plugins/post-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/post-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-snippets/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 3 replies
 * 2 participants
 * Last reply from: [davdebcom](https://wordpress.org/support/users/davdebcom/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/php-in-shortcode-doesnt-display-on-widgets/#post-9926341)
 * Status: resolved