Title: Insert PHP blocks not working correctly
Last modified: March 7, 2018

---

# Insert PHP blocks not working correctly

 *  [dxladner](https://wordpress.org/support/users/dxladner/)
 * (@dxladner)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/insert-php-blocks-not-working-correctly/)
 * Will, thanks for a awesome plugin. I am having an one issue. We are using Avada
   theme, with its page builder, I use a code block with the following code snippet:
 *     ```
       <script>
       $(document).ready(function () {
           var pdf = '[urlparam param="pdf" /]';
           var url = '[insert_php] echo esc_url(get_permalink(pdf)); [/insert_php]';
           window.location = url;
       });
       </script>
       ```
   
 * the problem line is this one: var url = ‘[insert_php] echo esc_url(get_permalink(
   pdf)); [/insert_php]’;
    upon redirect it sends me back a url value of
 * [http://dev.example.net/thank-you/%5Binsert_php%5D%20echo%20esc_url(get_permalink(pdf)](http://dev.example.net/thank-you/%5Binsert_php%5D%20echo%20esc_url(get_permalink(pdf)));%
   20[/insert_php].
 * So it is not parsing the Insert PHP tags correctly. Any help would be greatly
   appreciated.
 * Thanks,
 * Darren

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

 *  Thread Starter [dxladner](https://wordpress.org/support/users/dxladner/)
 * (@dxladner)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/insert-php-blocks-not-working-correctly/#post-10050478)
 * Will. I also tried to change it up using an example from your webpage. So I am
   following this example:
    [insert_php] $CookieName = “TestCookie”; $RedirectURL
   = “[http://example.com/page.html&#8221](http://example.com/page.html&#8221);;
   if( empty($_COOKIE[$CookieName]) ) { echo “<script type=’text/javascript’>location.
   href=’$RedirectURL'</script>”; } [/insert_php]
 * my new code block
    [ifurlparam param=”pdf”] [insert_php] $pdf = $_GET[‘pdf’];
   $RedirectURL = esc_url(get_permalink(pdf)); echo “<script>window.location =’$
   RedirectURL’;</script>”; [/insert_php] [/ifurlparam]
 * and now my new URL: [http://hldwp-dev.azurewebsites.net/thank-you/$RedirectURL](http://hldwp-dev.azurewebsites.net/thank-you/$RedirectURL).
 * again I cannot get the correct valued to be passed.
 *  [WillBontrager](https://wordpress.org/support/users/willbontrager/)
 * (@willbontrager)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/insert-php-blocks-not-working-correctly/#post-10060576)
 * Darren, I apologize my delayed reply.
 * Try this to see what value esc_url(get_permalink(pdf)) provides.
 *     ```
       <pre>
       [insert_php] echo get_permalink(pdf); [/insert_php]
       <hr>
       [insert_php] echo esc_url(get_permalink(pdf)); [/insert_php]
       </pre>
       ```
   
 * Note that the pdf value may need to be in quotes, as get_permalink(“pdf”) and
   esc_url(get_permalink(“pdf”))
 * If you get values, you can see what is being inserted into your JavaScript.
 * If you get no values, which is possible because both get_permalink() and esc_url()
   may be outside the scope of Insert PHP, then check your error logs. There may
   be a typo in the code or it may be a scope issue. Typos can be fixed. But a scope
   issue is rather permanent.
 * Will
    -  This reply was modified 8 years, 2 months ago by [WillBontrager](https://wordpress.org/support/users/willbontrager/).

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

The topic ‘Insert PHP blocks not working correctly’ is closed to new replies.

 * ![](https://ps.w.org/insert-php/assets/icon-256x256.gif?rev=3523853)
 * [Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts](https://wordpress.org/plugins/insert-php/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php/reviews/)

## Tags

 * [Parsing](https://wordpress.org/support/topic-tag/parsing/)

 * 2 replies
 * 2 participants
 * Last reply from: [WillBontrager](https://wordpress.org/support/users/willbontrager/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/insert-php-blocks-not-working-correctly/#post-10060576)
 * Status: not resolved