• Resolved Dandydahlia

    (@dandydahlia)


    Hi

    I’m loving your plugin thank you.

    I’m not sure what I’m doing wrong and was hoping for some guidance please. When I add a new snippet for a specific Gravity Form ID, it runs beautifully on that form all over my site.

    But if I only want that snippet to run on ONE specific page eg. mysite.com/my-test-page/ and enable Smart Conditional Logic with Page URL Contains my-test-page, it doesn’t run at all. (see image at https://ibb.co/d4hVTSj)

    I’m not sure what I’m doing wrong. I’ve left “Insert method” as Run Everywhere – do I need to change that when I change Smart Conditional Logic? (I did try the shortcode method, but when I inserted this in the page, above my gravity form it crashed the page)

    I’d only like the PHP snippet to run on that particular page, not be called on every single page, if possible please.

    Also – do you have a way for me to check if the PHP snippet is actually running? using Chrome Dev tools or similar.

    Thanks in advance 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @dandydahlia,

    Thank you for your feedback! We’re happy to hear you like the plugin.

    The issue here is that the check you are using is not available so early, when the Run Everywhere location is used.

    In the latest version of WPCode (2.0.8+) we added a new location called “Frontend Conditional Logic” for that exact reason and it should be automatically selected when you enable the conditional logic for the first time. That should allow you to use the conditional logic rules as you intended.

    Please try updating the auto-insert location to Frontend Conditional Logic and if you don’t see that option please update the plugin to 2.0.8+

    Thread Starter Dandydahlia

    (@dandydahlia)

    Wonderful! Thank you so much for replying.

    Will update and try again 🙂

    Thread Starter Dandydahlia

    (@dandydahlia)

    Hi Mircea,

    I updated the plugin and selected Frontend Conditional Logic but I couldn’t get it to work. So I deleted the Code and recreated it, and it still isn’t working. Any ideas please? https://ibb.co/SK4MnGr

    I also tried switching it to run everywhere and it worked, so it’s something about the conditional logic as switching back (to the image above) I can’t get it to work sadly.

    Is there another thing that could be causing it or do you have a way for me to check if the PHP snippet is actually running? using Chrome Dev tools or similar please.

    Thank you!

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @dandydahlia,

    Thank you for the update. There’s no way to see if the snippet is running from dev tools because when the snippet is not loaded it will not add anything to the output of the page.

    I think in this case the problem is that the code in your snippet is using a filter that runs early, before the hook used for the Frontend Conditional Logic is executed and so you can’t use the conditional logic that early in the page loading logic.

    Can you please reach out via the form at https://wpcode.com/contact so that you can share the snippet code privately with us?

    Thread Starter Dandydahlia

    (@dandydahlia)

    Thanks Mircea, I appreciate your reply.

    Oh that sounds like it must be it. It’s using the below filter, targeted at a particular form.

    add_filter( 'gform_email_background_color_label', 'change_label_bg_color', 10, 3 );
    function change_label_bg_color( $color, $field, $lead )

    If there is a way to see the snippet in dev tools, when it’s running on all the pages, please let me know? Thank you 🙂

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @dandydahlia,

    Yes, that filter is used in the email sent when the form is submitted so at that time the URL is likely one of an AJAX endpoint and not relevant to the page where the form is loaded as it happens in the background.

    I think in this case if you want that code to change just the labels for that specific form you are going to have to find a way to determine the form id from the code.

    If you want to limit where the snippet runs for other reasons, there’s no need, as the code will actually only get executed when the email is sent so it should have no other effect on the site.

    Regarding seeing a snippet in the dev tools – I mentioned in my previous reply that there’s no way to see from the dev tools when a snippet is running or not unless it adds some kind of output to the page. In this case, because you are calling a filter that will not be used until the form is submitted, the snippet shouldn’t change anything in the output of the page. When you use the dev tools in a browser you are looking at the rendered page in HTML after all the PHP execution is done so unless we specifically add some type of reference to the snippets that ran there’s no way to see which ones ran at that point, with the exception mentioned above – if the snippet makes a change in the actual output.

    Thread Starter Dandydahlia

    (@dandydahlia)

    Oh I see. That makes sense.

    Thanks so much Mircea. You’ve been a great help! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PHP Snippet – Run only on specific page’ is closed to new replies.