Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Possible Duplicate:
Shortcode always displaying at the top of the page

I've read what others have said here and at wordpress, but their answers don't fix my problem. Here is a very simple bit of code that reflects the problem (note, this is not the code I'm actually using, but a simple example that shows how the code works)..namely, regardless of anything you put above the shortcode (like a description), the shortcode always goes first. I've tried using return instead of echo, but that doesn't work.

   add_shortcode('my_shortcode','my_shortcode_function');


    function my_shortcode_function{

     my_function;

       }



        function my_function {
           for ($i=1;$i<=4;$i=$i+1){

     echo 'hello';

        }

}

Can anybody see what I might be doing wrong? Thanks for any help you can provide.

share|improve this question
"I've tried using return instead of echo, but that doesn't work." - in which sense did this not work? what is the real shortcode you are trying to program? – Michael Jul 31 '12 at 23:12
1  
Welcome to StackExchange! Please be sure to search the site for related questions before posting new questions. – Chip Bennett Jul 31 '12 at 23:27

marked as duplicate by Chip Bennett, toscho Aug 1 '12 at 1:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Shortcode functions should return content, not echo it.

share|improve this answer
right..but if you put in return my_function, it still has the same problem...is that what you mean by returning the content in my example? – Allen Aug 1 '12 at 0:34
ok...it looks like I can't do it the way I have it...yes, return is correct, but you can't have an intermediate function like I had it – Allen Aug 1 '12 at 1:04
Yes you can, but the intermediate function needs to return it too!!! (you can use output buffering otherwise). – TheDeadMedic Aug 1 '12 at 9:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.