Ask your WordPress questions! Pay money and get answers fast! (more info)

echo php within existing php code WordPress

  • SOLVED

How do I echo the following:

echo (get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000

I've tried like this but it simply prints echo (get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000 on the page

$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">' . __( "<em><strong>echo (get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000';</strong></em>", 'woocommerce' ) .'</label> etc...

Answers (3)

2013-08-12

Arnav Joy answers:

try this
$fwds_interval = (get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000';
$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">' .$fwds_interval .'</label>';


willcm comments:

this works perfectly

2013-08-12

Remy answers:

Why is there a translation function for numbers ?

You should insert the result in a var instead of using echo

$fwds_interval = get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000;


willcm comments:

okay so it becomes this?


$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">$fwds_interval</label>


willcm comments:

sorry:

$fwds_interval = get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000;

$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">$fwds_interval</label>


Remy comments:

$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">' . $fwds_interval . '</label>';

2013-08-12

Giri answers:

$option = get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000' ;
$comment_form['comment_field'] = '<div class="comment-form-rating-wrap"><p class="comment-form-rating"><label for="rating">' . __( $option, 'woocommerce' ) .'</label> etc...


willcm comments:

this

$option = get_option('fwds_interval') != '') ? get_option('fwds_interval') : '2000' ;

gives me this:

Parse error: syntax error, unexpected ')'

??