Title: Shortcode function &#8211; replacing echo with return &#8211; need help
Last modified: September 1, 2016

---

# Shortcode function – replacing echo with return – need help

 *  [gsacheli](https://wordpress.org/support/users/gsacheli/)
 * (@gsacheli)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/shortcode-function-replacing-echo-with-return-need-help-1/)
 * Hello, I’m new to writing WP plugins and after I wrote this code, I saw that 
   the code is executed before the content of the page. Now I know I should had 
   used return instead of echo. Any help how can I change the code? I am a real 
   php beginner 🙂
 *     ```
       <?php
       $permalink = get_permalink();
       $now = time();
       $compare_time = mktime(0, 0, 0, 1, 1, 2016);
       $post_time = get_post_time('U');
       $url03 = str_replace('https://', 'http://', $permalink );
   
       if ($post_time < $compare_time) {
   
       echo '<div class="g-comments" data-href="';
       echo $url03 . '"';
       echo ' data-width="700" ';
       echo 'data-first_party_property="BLOGGER" ';
       echo 'data-view_type="FILTERED_POSTMOD">';
       echo '</div> ';
   
       }
       else {
   
       echo '<div class="g-comments" data-href="';
       echo the_permalink() . '"';
       echo ' data-width="700" ';
       echo 'data-first_party_property="BLOGGER" ';
       echo 'data-view_type="FILTERED_POSTMOD">';
       echo '</div> ';
       }
       ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [Dave Mackey](https://wordpress.org/support/users/davidshq/)
 * (@davidshq)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/shortcode-function-replacing-echo-with-return-need-help-1/#post-8797320)
 * I am running into the same issue, not sure if you ever resolved this, but here
   is the StackOverflow article I’ve found to be helpful thus far:
    [http://wordpress.stackexchange.com/questions/191759/shortcode-output-always-before-content](http://wordpress.stackexchange.com/questions/191759/shortcode-output-always-before-content)

Viewing 1 replies (of 1 total)

The topic ‘Shortcode function – replacing echo with return – need help’ is closed
to new replies.

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [Dave Mackey](https://wordpress.org/support/users/davidshq/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/shortcode-function-replacing-echo-with-return-need-help-1/#post-8797320)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
