Title: My code is not executing
Last modified: February 9, 2026

---

# My code is not executing

 *  Resolved [fabx77](https://wordpress.org/support/users/fabx77/)
 * (@fabx77)
 * [3 months, 4 weeks ago](https://wordpress.org/support/topic/my-code-is-not-executing/)
 * Hello
   1/ I created some code, but it doesn’t execute, even though it’s active.
 * 2/ I added a display of the contents of my variables (ACF), but I don’t see them.
   Neither on the website screen nor in the debug.log file.
 * For example, I’m using:
 * echo ‘Hello’;
 * var_dump ($name_variable);
 * error_log( print_r( $acf_name_variable) );
 * do_action( ‘inspect’, [ ‘variable_name’, $acf_name_variable ] );
 * ps:_ In my wp-config.php file, all “debug\_XXX” entries are set to true._
 * Thank you very much for your help!

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

 *  Plugin Author [Carolina](https://wordpress.org/support/users/carolinaop/)
 * (@carolinaop)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/my-code-is-not-executing/#post-18818381)
 * Hi [@fabx77](https://wordpress.org/support/users/fabx77/),
 * Thanks for reaching out! I had a look at your message, and from what you’ve shared,
   it doesn’t look like the issue is directly related to the Code Snippets plugin
   itself. The plugin’s job is to safely run your PHP code, but it can’t fix or 
   debug the code logic itself — that part still works just like it would in your
   theme’s _functions.php_ file.
 * That said, I’d love to help you get things working! Here are a few things to 
   check:
 * **1. Where is your snippet set to run?**
   Make sure your snippet is set to run
   in the right context. If it’s meant to run on the front end, choose “Only run
   on site front-end” or “Run everywhere” when creating the snippet.
 * **2. Are you using the right hooks?**
   If your code depends on WordPress loading
   certain things (like ACF fields), you might need to wrap it in an action hook
   like:`add_action( 'wp', function() { // your code here });`
 * **3. Debugging output**
   – `echo` and `var_dump` won’t show anything if the code
   runs before the page output starts or in the wrong context.– `error_log()` should
   work if _WP\_DEBUG_ and _WP\_DEBUG\_LOG_ are both set to `true` in your _wp-config.
   php_. Make sure you’re checking the right _debug.log_ file (usually in _wp-content_).
 * Let us know if this helps!
 *  Thread Starter [fabx77](https://wordpress.org/support/users/fabx77/)
 * (@fabx77)
 * [3 months, 2 weeks ago](https://wordpress.org/support/topic/my-code-is-not-executing/#post-18829898)
 * Hi Caroline,
 * **Thank you so much for your information!**
 * I have to add `var_dump($name_variable);` to my procedure because I’ve noticed
   that my code isn’t executing and I can’t even see the variables displayed by 
   another plugin called “variable_inspector”.
 * I have four options in your plugin to run the code:
    - Run everywhere
    - Run only in the admin area
    - Run only in the public interface
    - Run only once
 * I’ve tried each one, but the code still doesn’t run… Here’s just the beginning
   of my code:
 * ==================================================================
 * // Create a cron job to run the day after an event happens or ends
   function set_expiry_date(
   $post_id ) {
 * / // See if an event_end_date or event_date has been entered, and if not, then
   end the function
 * if( get_post_meta( $post_id, $key = ‘date_de_latelier’, $single = true ) ) {
 * / // Get the end date of the event in Unix grenwich mean time
   $acf_date_de_latelier
   = get_post_meta( $post_id, $key = ‘date_de_latelier’, $single = true );
 * var_dump($acf_date_de_latelier);
   do_action(‘inspect’, [‘variable_name’, $acf_date_de_latelier]);
 * } else {
 * // No start or end date. Lets delete any CRON jobs related to this post and end
   the function.
   wp_clear_scheduled_hook(‘make_past_event’, array($post_id));return;}
 * ……
 * The “workshop_date” variable is, of course entered for each article.
 * Thank you.
 * ps:_WP\_DEBUG and WP\_DEBUG\_LOG are indeed enabled in the config.php file._
    -  This reply was modified 3 months, 2 weeks ago by [fabx77](https://wordpress.org/support/users/fabx77/).
 *  Plugin Author [Carolina](https://wordpress.org/support/users/carolinaop/)
 * (@carolinaop)
 * [3 months, 1 week ago](https://wordpress.org/support/topic/my-code-is-not-executing/#post-18838150)
 * Hi [@fabx77](https://wordpress.org/support/users/fabx77/),
 * Thank you for the detailed explanation and code sample.
 * From what you’ve described, this doesn’t indicate an issue with the Code Snippets
   plugin itself. When a snippet is active, our plugin loads it the same way WordPress
   loads code from a theme’s `functions.php` file. However, defining a function 
   does not automatically execute it.
 * In your example, you are defining:
 * `function set_expiry_date( $post_id ) {`
 * But this function will only run if it is attached to a WordPress hook (for example`
   save_post`) or called somewhere else in your code. If it is not hooked or called,
   it will never execute — which would explain why:
    - `var_dump()` shows nothing
    - `echo` shows nothing
    - `error_log()` does not write anything
    - Variable Inspector does not display anything
 * Additionally, please make sure:
    - You are using straight quotes (`'`) and not curly/smart quotes (`‘ ’`), as
      those will break PHP execution.
    - The snippet does not contain malformed comments.
    - The function is properly attached to the correct WordPress or ACF hook so 
      that `$post_id` is actually available when it runs.
 * Since Code Snippets only executes the PHP code safely but does not alter how 
   WordPress hooks or ACF logic works, the behavior you’re seeing is consistent 
   with the function simply not being triggered.
   To quickly confirm that Code Snippets
   is executing properly, please try this php test snippet:
 * `add_action( 'init', function () {
   error_log( 'Code Snippets test: snippet executed
   successfully.' );} );
 * **How to test it:**
    1. Add this as a new snippet.
    2. Set it to **Run everywhere**.
    3. Visit any page of your site.
    4. Check your `wp-content/debug.log` file (or your server’s PHP error log).
 * If you see this line in the log: “Code Snippets test: snippet executed successfully.”
 * If you’re experiencing an issue specifically with the snippet not saving or activating
   properly, please let us know which plugin version you’re using and we’ll be happy
   to investigate further.
 * Let us know if this helps.
 *  Plugin Author [Carolina](https://wordpress.org/support/users/carolinaop/)
 * (@carolinaop)
 * [2 months, 1 week ago](https://wordpress.org/support/topic/my-code-is-not-executing/#post-18863327)
 * Hello [@fabx77](https://wordpress.org/support/users/fabx77/)
 * Since we haven’t received any further feedback, I’ll go ahead and close this 
   ticket for now. Please feel free to reopen it at any time if needed—we’ll be 
   happy to assist 🙂

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

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fmy-code-is-not-executing%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

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

 * 4 replies
 * 2 participants
 * Last reply from: [Carolina](https://wordpress.org/support/users/carolinaop/)
 * Last activity: [2 months, 1 week ago](https://wordpress.org/support/topic/my-code-is-not-executing/#post-18863327)
 * Status: resolved