0

I need to correct this code, I don't know why my PHP is commented out every time:

$output = '<ul class="custom_code">
    <li class="custom_code">
    <?php echo wpfp_link(); ?>
    </li></ul>';

return $output; 

1
  • you're already in php <?php echo wpfp_link(); ?> so get rid of the PHP tags. Commented Aug 24, 2015 at 19:12

5 Answers 5

3

echo runs immediately. It doesn't return anything. So your code is effectively running as if it was written like this:

echo wpfp_link();
$output = '<ul blah blah blah</ul>';
return $output;

Given you're dealing with wordpukepress, you probably want something more like

$output = '<ul blah blah ' . get_wpfp_link() . '...</ul>';
return $output;

As well, PHP is not resursively embeddable, as you have. This code will not work as you think it would:

<?php
echo '<?php echo 'foo' ?>';
?>

This will output <?php echo 'foo' ?>, not just 'foo'.

Sign up to request clarification or add additional context in comments.

Comments

1

You can concatenate the string with .

$output = '<ul class="custom_code"><li class="custom_code">'.wpfp_link().'</li></ul>';

return $output; 

Comments

1
$output = '<ul class="custom_code"><li class="custom_code">'.wpfp_link().'</li></ul>';

return $output; 

definitely will works. BUT we sure that you don't use short php tags /or they turned on in php.ini

so all this should looks like:

function print_li(){
$output = '<ul class="custom_code"><li class="custom_code">'.wpfp_link().'</li></ul>';    
return $output;     
}

where wpfp_link returns a list with <li> tags.

Comments

0

Not sure if it works like this but you can try.

$output = '<ul class="custom_code">
 <li class="custom_code">'.wpfp_link().'
</li></ul>';
return $output;

Comments

0

Do it like this:

$funcout = wpfp_link();
return "<ul class=\"custom_code\"><li class=\"custom_code\">{$funcout}</li></ul>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.