Title: Code String Not Executing Properly / User Error?
Last modified: August 21, 2016

---

# Code String Not Executing Properly / User Error?

 *  Resolved [Doctor Psyringe](https://wordpress.org/support/users/nicholasdesuza/)
 * (@nicholasdesuza)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/code-string-not-executing-properly-user-error/)
 * Ok, so I’ve been coding up loads of ads for my website to get that extra revenue
   edge. But I want my Authors to have the Ability to not only change the Ad Content,
   but Enable it and Disable it.
 * So – for all of my custom post types and regular post types/pages – the following
   works in conjunction with my WordPress Editor User Interface;
 * <?php if(!$oswc_widget_ad_hide) { ?>
    <table style=”width: 300px;” border=”0″
   > <tbody><tr><td> <?php if ($widgetadvertisement) { ?> <?php echo $widgetadvertisement;?
   > <?php } else { ?> <script>adcodeirrelevant</script> <?php } ?> </td></tr><tr
   > <td style=”text-align: center;”> <span style=”font-size: xx-small;”>Advertisement
   </span> </td></tr></tbody> <?php } ?>
 * oswc_widget_ad_hide – Enable or Disable
    widgetadvertisement – The Content, with
   a Default if no is data provided.
 * This code doesn’t work in the widget. In fact, the same effect occurs then I 
   plug that .php into a Unwrapped Text as this PHP Widget, so perhaps I already
   have .php enabled and the goal of this code should be resolved elsewhere. Nonetheless,
   it damages the template, moves the footer to the sidebar. Ok… so maybe that code
   is wrong for the purpose, being outside “the loop”. Of course I coded a version
   using a variation of;
 * <?php global $wp_query;
    if(is_object($wp_query->queried_object) && $wp_query-
   >queried_object->ID) { echo get_post_meta($wp_query->queried_object->ID, ‘customfieldname’,
   true); } ?>
 * Not that I got that working either, if anything it damaged the code and turned
   the widget into a title line. By the way, saying there is a method to get this
   code working, is this widget available Unwrapped, surprised it’s not available
   in that form.
 * Thanks!
 * [https://wordpress.org/plugins/php-code-widget/](https://wordpress.org/plugins/php-code-widget/)

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

 *  Thread Starter [Doctor Psyringe](https://wordpress.org/support/users/nicholasdesuza/)
 * (@nicholasdesuza)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/code-string-not-executing-properly-user-error/#post-4695095)
 * After further research I’m fairly positive this is a user error demanding these
   variables must be declared Global then called, I’ll report back after a hopefully
   swift resolution.
 *  Plugin Author [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [12 years, 1 month ago](https://wordpress.org/support/topic/code-string-not-executing-properly-user-error/#post-4695182)
 * Yep. Globals will get you if you’re not careful. Code in the widget does not 
   run in the global context.
 * [https://wordpress.org/plugins/php-code-widget/faq/](https://wordpress.org/plugins/php-code-widget/faq/)

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

The topic ‘Code String Not Executing Properly / User Error?’ is closed to new replies.

 * ![](https://ps.w.org/php-code-widget/assets/icon.svg?rev=992095)
 * [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-code-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-code-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/php-code-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-code-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-code-widget/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/code-string-not-executing-properly-user-error/#post-4695182)
 * Status: resolved