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?

2
  • var_dump($content) gives me string(0) ""
    – Fabian
    Jan 15, 2015 at 9:36
  • Of course it will return "empty" - remove the if line in your shortcode handler. Jan 15, 2015 at 16:37

1 Answer 1

-1
function homepage_featuredproducts( $atts , $content = null ) {
  if( empty( $content ) ) 
     $content='no content to display';

  return $content;

}
add_shortcode( 'homepage_featuredproducts', 'homepage_featuredproducts' );
1
  • Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Jan 15, 2015 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.