Title: shortcode return string problems
Last modified: August 20, 2016

---

# shortcode return string problems

 *  Resolved [Rob](https://wordpress.org/support/users/roballred/)
 * (@roballred)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/)
 * i have a simple shortcode that i want to return a permalink with some h2 tags
   around it. below you can see my two samples the first one just returns a string
   with and the other gets the permalink with <h2>’s around it. I put the <h2>’s
   around the test case to make sure they werent getting filtered out. any suggestions?
 * function demolistposts_handler() {
    $retVal = ‘<h2>hello earthlings</h2>; return
   $retVal; }
 * this returns what i would expect but the following returns
    the link with no 
   tags function demolistposts_handler() { $temp_link = the_permalink(); $retVal
   = ‘<h2>$temp_link</h2>; return $retVal; }

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/#post-2404277)
 * [http://php.net/manual/en/language.types.string.php](http://php.net/manual/en/language.types.string.php)
 * try either:
 * `$retVal = '<h2>'.$temp_link.'</h2>';`
 * or:
 * `$retVal = "<h2>$temp_link</h2>";`
 * also, you need to use `get_permalink()`, possibly like so `get_permalink($post-
   >ID)`, for which you might need to set `$post` as a global variable: `global 
   $post;`
 * i.e. the full code:
 *     ```
       function demolistposts_handler() {
       global $post;
       $temp_link = get_permalink($post->ID);
       $retVal = '<h2>'.$temp_link.'</h2>';
       return $retVal;
       }
       ```
   
 *  Thread Starter [Rob](https://wordpress.org/support/users/roballred/)
 * (@roballred)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/#post-2404281)
 * ok that worked, seems like problem was where i was getting the permalink from.
   the value from get_permalink($post->ID) works and the value from the_permalink()
   doesn’t. I don’t really understand the difference in the return strings, but 
   know i have a way that works. thank you.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/#post-2404289)
 * > the value from get_permalink($post->ID) works and the value from the_permalink()
   > doesn’t
 * the_permalink _**echos **_the value (out to the screen), while get_permalink _**
   returns **_the value for further use in strings, for instance.
    example: `$link
   = get_permalink($post->ID);`
 * [http://codex.wordpress.org/Function_Reference/the_permalink](http://codex.wordpress.org/Function_Reference/the_permalink)
   
   [http://codex.wordpress.org/Function_Reference/get_permalink](http://codex.wordpress.org/Function_Reference/get_permalink)
 * there are many functiosn in wordpress where the function name starts with `the_`
   which echo the result (direct output); and equivalent functions starting with`
   get_` which return the result (to use in strings, for instance).
 *  Thread Starter [Rob](https://wordpress.org/support/users/roballred/)
 * (@roballred)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/#post-2404302)
 * thanks again.

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

The topic ‘shortcode return string problems’ is closed to new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [Rob](https://wordpress.org/support/users/roballred/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/shortcode-return-string-problems/#post-2404302)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
