简体   繁体   中英

Inserting an image into PHP code if custom field = true

I have the following code which is pulling in a custom field named phone.

<?php echo get_post_meta( get_the_ID(), 'ecpt_phone', true ); ?>

I additionally however want to add a little icon to the left of it. So I realise I have to include the src link somewhere, have tried the below, but am having no joy. Sorry a bit new...

<?php
$value = get_post_meta( get_the_ID(), 'ecpt_phone', true );
if( $value == 'True' ) { echo '<img src="/wp-content/uploads/2013/02/image.png">'; echo get_post_meta( get_the_ID(), 'ecpt_phone', true ); ?>

Thanks so much in advance.

尝试在字符串定义中反转'和'。这导致

"<img src='/wp-content/uploads/2013/02/image.png'>";

src删除第一个/ ,然后尝试。

echo '<img src="wp-content/uploads/2013/02/image.png">';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM