admin管理员组

文章数量:1323157

I am writing a WordPress plugin that will display a devotional image. One of the options I would like to include is image width. I am trying to wrap the image and some text in a div so I can style it and let the user chose some different styling options. However, just trying to set the div width using the variable is not working. It says there is a syntax error.

Any help would be appreciated! Thanks, Nick.

$imageWidth = get_option('devotional_imageWidth','100%');   
    
$content = "<h2>Devotionally Images</h2>";

<div style="width:$imageWidth;">
    print '<img src="' .$show_file. '" alt="Image Title Here">';
    $content .= "devotional by Devotional.ly";          
</div>

    return $content;
}
add_shortcode('devotionally','devotionally_function');

I am writing a WordPress plugin that will display a devotional image. One of the options I would like to include is image width. I am trying to wrap the image and some text in a div so I can style it and let the user chose some different styling options. However, just trying to set the div width using the variable is not working. It says there is a syntax error.

Any help would be appreciated! Thanks, Nick.

$imageWidth = get_option('devotional_imageWidth','100%');   
    
$content = "<h2>Devotionally Images</h2>";

<div style="width:$imageWidth;">
    print '<img src="' .$show_file. '" alt="Image Title Here">';
    $content .= "devotional by Devotional.ly";          
</div>

    return $content;
}
add_shortcode('devotionally','devotionally_function');
Share Improve this question edited Sep 2, 2020 at 7:41 Hector 6821 gold badge7 silver badges18 bronze badges asked Sep 1, 2020 at 19:20 Nick LNick L 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

There are invalid PHP codes in your sample. Try to use valid PHP code like below.

$imageWidth = get_option('devotional_imageWidth','100%');   
    
$content = "<h2>Devotionally Images</h2>";

$content .= '<div style="width:' . $imageWidth. ';">';
$content .= '<img src="' .$show_file. '" alt="Image Title Here">';
$content .= "devotional by Devotional.ly";          
$content .= '</div>';

    return $content;

本文标签: phpTrying to use a variable to set image width