Title: Php and shortcodes
Last modified: April 2, 2020

---

# Php and shortcodes

 *  Resolved [sulive](https://wordpress.org/support/users/sulive/)
 * (@sulive)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/)
 * Hi,
 * I’m using a plugin to restrict certain content by using a shortcode the plugin
   has provided.
 * Now I want to use this shortcode only when someone is logged in.
 * So my php code on my WordPress page is:
 * <?php
    if ( is_user_logged_in() ) { echo “[pms-register]”; } ?>
 * But this doesn’t work. Does someone know the solution?
 * Thanks,
    Sylvia

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12617947)
 * use [do_shortcode()](https://developer.wordpress.org/reference/functions/do_shortcode/)
 *  Thread Starter [sulive](https://wordpress.org/support/users/sulive/)
 * (@sulive)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12617966)
 * Many thanks Steve!
 * Sylvia
 *  Thread Starter [sulive](https://wordpress.org/support/users/sulive/)
 * (@sulive)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618179)
 * Quick question, suppose I have shortcodes that have parameters with double quotes.
   I tried using \ to escape it but it doesnt work. Can you help?
 * echo do_shortcode( ‘[pay name=”Form name” description=”Payment description”]’);
   
   echo do_shortcode( ‘[pay_field type=”Email” label=”Your email” required=”true”/]’);
 * Thanks
    Sylvia
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618209)
 * Double quotes are OK when inside single quotes. You’d only have to escape if 
   you had double quoted strings inside a double quoted string.
 *  Thread Starter [sulive](https://wordpress.org/support/users/sulive/)
 * (@sulive)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618237)
 * It doesn’t work
 * [pay_field type=”label” label=”Product ABC for €19,95″ amount=”19,95″ /]
    [pay_total/][
   pay_button label=”Pay” /] [/pay]
 * For instance I can see the last command whereas the code above is parsed
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618256)
 * If do_shortcode returns the string you provided, then it’s not finding the shortcode(
   in this case, the shortcode [pay])
 *  [Carike](https://wordpress.org/support/users/carike/)
 * (@carike)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618295)
 * [https://developer.wordpress.org/reference/functions/is_user_logged_in/](https://developer.wordpress.org/reference/functions/is_user_logged_in/)
 * `is_user_logged_in()` returns TRUE or FALSE.
 * So you would use something like
 *     ```
       <?php
       if (is_user_logged_in() === TRUE)
          { echo '[pms-register]'; }
       ?>
       ```
   
 *  Thread Starter [sulive](https://wordpress.org/support/users/sulive/)
 * (@sulive)
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618506)
 * Yes so the shortcode that I need in php is:
 * [pay name=”Form name” description=”Payment description”]
    [pay_field type=”email”
   label=”Your email” required=”true” /] [pay_field type=”label” label=”Product 
   ABC for €19,95″ amount=”19,95″ /] [pay_total /] [pay_button label=”Pay” /] [/
   pay]
 * I added echo do_shortcode. When I click on the Pay button it says that the amount
   it not valid.
 * Thanks
    Sylvia
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618547)
 * Contact the dev of the plugin that’s provide the shortcode(s) as your code is
   correct, as far as I can see.

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

The topic ‘Php and shortcodes’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 9 replies
 * 3 participants
 * Last reply from: [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/php-and-shortcodes/#post-12618547)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
