0

An add_action will only give content back if you call echo in the function and does nothing when using return, why?

WORKS:

add_action( 'rss2_item', 'custom_enclosure' );
function custom_enclosure() {
  global $post;    
  $output  = 'Hello World';    
  echo $output;
};

DOES NOT WORK:

add_action( 'rss2_item', 'custom_enclosure' );
function custom_enclosure() {
  global $post;    
  $output  = 'Hello World';    
  return $output;
};

With add_filter one needs to use return, but echo also works?!?!

function insert_post_related($content) {
  $content = "Hello World";
  return $content;
}
add_filter('the_content','insert_post_related');

It confuses the f*#& out of me and I have wasted 4 hours right now because I used return on an add_action instead of echo. For add_filter one can use both return or echo, why is that?

What is the convention here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.