0

I use a shortcode on my page like

[homepage_featuredproducts]test[/homepage_featuredproducts]

In my functions.php

function homepage_featuredproducts( $atts , $content = null ) {
  if('{{emtpy}}'!=$content) $content='empty';
  return $content;

}
add_shortcode( 'homepage_featuredproducts', 'homepage_featuredproducts' );

And in my template somewhere

<p><?php echo do_shortcode( '[homepage_featuredproducts]' ) ?></p>

And it allways returns "empty".

Why cant I get the content between the shortcodes in my function and return it?

  • var_dump($content) gives me string(0) "" – humpdi Jan 15 '15 at 9:36
  • Of course it will return "empty" - remove the if line in your shortcode handler. – TheDeadMedic Jan 15 '15 at 16:37
-1
function homepage_featuredproducts( $atts , $content = null ) {
  if( empty( $content ) ) 
     $content='no content to display';

  return $content;

}
add_shortcode( 'homepage_featuredproducts', 'homepage_featuredproducts' );
  • Please add an explanation to your answer: why could that solve the problem? – fuxia Jan 15 '15 at 10:29

Your Answer

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

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