Title: Php code inside wordpress do_shortcode
Last modified: August 16, 2020

---

# Php code inside wordpress do_shortcode

 *  [Epiphany](https://wordpress.org/support/users/epiphany1/)
 * (@epiphany1)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/)
 * Hi
    I want to add a php code inside the wordpress do shortcode The shortcode [
   link] is a mycred shortcode which gives users points when they click on a link.
   However I want to give my users link when the share a post on facebook so I have
   used the code below, but it did not work
 *     ```
       <?php
       echo do_shortcode( '[link href="http://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode(get_permalink()); ?>"]View portfolio[/link]'); ?>
       ```
   
 * I tried the above code but it didn’t work. It didn’t recognize the php code after
   the facebook share link. See the URL it shows below
 * [http://www.facebook.com/sharer/sharer.php?u=%3C?php%20echo%20urlencode(get_permalink()](http://www.facebook.com/sharer/sharer.php?u=%3C?php%20echo%20urlencode(get_permalink()));%
   20?%3E
    -  This topic was modified 5 years, 7 months ago by [Epiphany](https://wordpress.org/support/users/epiphany1/).

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13264794)
 * PHP is not executed inside a shortcode. That would be a serious security hole.
    -  This reply was modified 5 years, 7 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Thread Starter [Epiphany](https://wordpress.org/support/users/epiphany1/)
 * (@epiphany1)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13264808)
 * [@sterndata](https://wordpress.org/support/users/sterndata/)
    Thanks for your
   fast reply sir. Is there no other way to achieve that. Even if it’s a php function.
   I have little knowledge of php.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13264814)
 * You might ask the mycred folks, since it’s their shortcode. I recommend asking
   at [https://wordpress.org/support/plugin/mycred/#new-post](https://wordpress.org/support/plugin/mycred/#new-post)
   so the plugin’s developers and support community can help you with this.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13270257)
 * You cannot nest PHP blocks and PHP code cannot be passed to do_sbortcode() per
   se, but you can concatenate the string passed to do_shortcode(). For example:
 *     ```
       <?php
         do_shortcode('[foo id="' . get_queried_object_id() . '"]');
       ?>
       ```
   
 *  Thread Starter [Epiphany](https://wordpress.org/support/users/epiphany1/)
 * (@epiphany1)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13271152)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/)
    Thank you very much
   for your help but I have little knowledge of php. I don’t understand the code
   above. Please can you provide me the full code. Thank you very much sir!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13276339)
 *     ```
       <?php
       echo do_shortcode( '[link href="http://www.facebook.com/sharer/sharer.php?u=' . urlencode( get_permalink()) . '"]View portfolio[/link]');
       ?>
       ```
   
 *  Thread Starter [Epiphany](https://wordpress.org/support/users/epiphany1/)
 * (@epiphany1)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13276651)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/)
    Wow thanks you so much
   for the code it worked perfectly well. Thank you once again.

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

The topic ‘Php code inside wordpress do_shortcode’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [Epiphany](https://wordpress.org/support/users/epiphany1/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/php-code-inside-wordpress-do_shortcode/#post-13276651)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
