Title: Variable text between PHP code
Last modified: August 21, 2016

---

# Variable text between PHP code

 *  Resolved [estr](https://wordpress.org/support/users/estr/)
 * (@estr)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/)
 * Hello,
 * If someone could answer that. I have the following code:
 * =================================
    <?php if (is_single()) { ?>
 * <p>Random text that will be different for each post.</p>
 * <?php } ?>
    =================================
 * Is it somehow possible with this plugin for the random text that I want to be
   displayed, to be specified in the post itself? Because creating a unique snippet
   per post is excessive.
 * Thank you!
 * [http://wordpress.org/plugins/php-code-for-posts/](http://wordpress.org/plugins/php-code-for-posts/)

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

 *  Thread Starter [estr](https://wordpress.org/support/users/estr/)
 * (@estr)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098141)
 * Tried to put “<?php if (is_single()) { ?>” into [php snippet=1].
 * And “<?php } ?>” into [php snippet=2].
 * And then to do the following in the post:
 * [php snippet=1]
    <p>Random text that will be different for each post.</p> [php
   snippet=2]
 * But this does not work 🙁
 *  Thread Starter [estr](https://wordpress.org/support/users/estr/)
 * (@estr)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098143)
 * In the plugin description it is said that:
 * “The plugin also contains a variable array which you can add variables to for
   use between snippets called $_var and is available though the global variable
   $PHPPC which is an object, so its $PHPPC->_vars[]”
 * But I am not that advanced to understand how to use this or if this could be 
   used to solve my problem at all.
 *  Plugin Author [Jamie](https://wordpress.org/support/users/themissingcode/)
 * (@themissingcode)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098269)
 * Hi Estr,
 * as of version 1.1.1 you can now specify parameters to the plugin’s shortcode 
   using the parameter “param”.
 * you can specify the value of param in a name=value pair separated by &s.
 * For example `[php snippet=2 param="myvar=myval&othervar=otherval"]`.
 * There parameters can be accessed within your snippet using `$_parameters` variable.
 * for example: `echo $_parameters["myvar"];` would output “myval”
 * I hope this solves your issue.
 * Thanks,
    TMC
 *  Thread Starter [estr](https://wordpress.org/support/users/estr/)
 * (@estr)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098270)
 * Great, thank you!
 *  [nuteamfreedom](https://wordpress.org/support/users/nuteamfreedom/)
 * (@nuteamfreedom)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098277)
 * I have a similar question, but I need to insert a [shortcode] that calls a db
   field as my parameter/variable…
 * I’m not super great at php, so I may not be defining the parameters/variables
   within the php correctly…
 * In the snippet I have…
 * <?php
 * echo shortenURL(‘[http://aq155.nuteam.com/go/Opp/$_myvar&#8217](http://aq155.nuteam.com/go/Opp/$_myvar&#8217););
   ?
   >
 * then when I use the short code, I need the myvar = [iw_db_AffiliateID]
 * something like:
 * [php snippet=1 param=”myvar=[iw_db_db_AffiliateID]”
 * So, 2 questions…
 * 1. how do I define “myvar” within the snippet to be a parameter/variable
 * 2. Can I Use a shortcode/db field as the variable, and if so, how do I specify
   it in there?
 * Any help would be greatly appreciated by this newbie..
 * Thanks.
 *  [nuteamfreedom](https://wordpress.org/support/users/nuteamfreedom/)
 * (@nuteamfreedom)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098278)
 * nevermind…figured it out. thanks.

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

The topic ‘Variable text between PHP code’ is closed to new replies.

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

 * 6 replies
 * 3 participants
 * Last reply from: [nuteamfreedom](https://wordpress.org/support/users/nuteamfreedom/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/variable-text-between-php-code/#post-4098278)
 * Status: resolved