FilippoR
FilippoR

Reputation: 11

Show an echo function inside an echo function in a div

I am trying to display a variable inside a php function.

This is the code:

if ( is_user_logged_in() ) {
echo '<div id="cp_subbtn" class="cp_subbtn"><?php echo $l_continue; ?></div>' ; } else { echo 'You are not logged in.' ; }

What I get is just a stylized div ( class="cp_sbbtn" ), but I have no text displayed. I am trying to figure out how to display a variable ( $l_continue) text inside an echo function, like in this case.

Upvotes: 1

Views: 249

Answers (2)

Simas Joneliunas
Simas Joneliunas

Reputation: 3118

You are returning php code inside a string. This would execute the php code but would look for the $l_continue variable in the active php code on the page.

You therefore have to either:

  • make sure that the variable is defined and not null inside the php code on the page (the variable is currently not set hence you don't see any text printed out)
  • or return the variable value instead of the php code echo '<div id="cp_subbtn" class="cp_subbtn">'. $l_continue .'</div>' ; }

Upvotes: 0

Yogesh Patel
Yogesh Patel

Reputation: 712

Try this

if ( is_user_logged_in() ) { 
    echo '<div id="cp_subbtn" class="cp_subbtn">'.$l_continue.'</div>' ;
 }
 else { 
    echo 'You are not logged in.' ; 
 }

You can just concatenate string

Upvotes: 1

Related Questions