Title: [Plugin: Exec-PHP] Code not executed in a widget but ok when hard coded
Last modified: August 19, 2016

---

# [Plugin: Exec-PHP] Code not executed in a widget but ok when hard coded

 *  [ouranos2](https://wordpress.org/support/users/ouranos2/)
 * (@ouranos2)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/)
 * I want to display subcategories of current category in a widget. So i tested 
   exec-php and “exec-php / hello world” works fine.
 * The code I’m using (see below) works fine when hard-coded in the sidebar, but
   doesn’t display anything when i put it in a text widget.
 * I tried with no other active plugin, same result …
 * You can see the two widgets and the hard-coded result here, at the bottom of 
   the sidebar.
    [http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/](http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/)
 * Any idea ? Thanks.
 *     ```
       <?php
       if (is_category()) {
         $this_category = get_category($cat);
         if (get_category_children($this_category->cat_ID) != "") {
           wp_list_categories('orderby=id&show_count=0&title_li=
       &use_desc_for_title=1&child_of='.$this_category->cat_ID);
           }
       }
       ?>
       ```
   

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616710)
 * Try this widget:
    [http://wordpress.org/extend/plugins/php-code-widget/](http://wordpress.org/extend/plugins/php-code-widget/)
 *  Thread Starter [ouranos2](https://wordpress.org/support/users/ouranos2/)
 * (@ouranos2)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616821)
 * Thanks Otto, but i already tried it, and a bunch of other php plugins. I will
   try once more with php-code-widget, though, and after that i will bother you 
   with the same problem on your plugin page … 😉
 * F.
 *  Thread Starter [ouranos2](https://wordpress.org/support/users/ouranos2/)
 * (@ouranos2)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616822)
 * So, i tried again with php-code-widget. You can see the result at the same url:
   [http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/](http://www.xarax.fr/wpfsc4/rubrique/democratisation-de-la-science/)
   
   A php-code-widget “hello world”, no problem so far. But the code i try to execute(
   see above) give no result. Same code hard-coded in the sidebar, no problem (bottom
   of the sidebar).
 * Any idea from the Tech Ninja would be a great help … 😉
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616844)
 * Your code doesn’t have `$cat` defined. Where is that variable supposed to be 
   coming from?
 *  Thread Starter [ouranos2](https://wordpress.org/support/users/ouranos2/)
 * (@ouranos2)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616930)
 * Sorry Otto, but I’ve got no php skill at all … The variable is the current category
   in the url ? What i don’t understand is why this exact same code works fine when
   i don’t use any plugin (when the code is in the sidebar template) and why it 
   doesn’t work with a “php-widget-plugin” ?

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

The topic ‘[Plugin: Exec-PHP] Code not executed in a widget but ok when hard coded’
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/exec-php.svg)
 * [Exec-PHP](https://wordpress.org/plugins/exec-php/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/exec-php/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/exec-php/)
 * [Active Topics](https://wordpress.org/support/plugin/exec-php/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/exec-php/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/exec-php/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [ouranos2](https://wordpress.org/support/users/ouranos2/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-exec-php-code-not-executed-in-a-widget-but-ok-when-hard-coded/#post-1616930)
 * Status: not resolved