I have a snippet of code that basically says to show a field if it's populated. It's an Advanced Custom Field text field.
Here's the working code:
<?php if (get_field('oil_pdf')): ?>
<img src="<?php echo esc_url( home_url( '/' ) ); ?>media/oil-icon-pdf.png"></a>
<?php endif; ?>
I need to change the code to only show if the text field (oil_pdf) includes '.pdf' somewhere in the text string. Not just 'pdf' but '.pdf'
Is this possible?
Hariprasad Vijayan answers:
Hi,
Try this,
<?php if (get_field('oil_pdf') && strpos(get_field('oil_pdf'),'.pdf') !== false): ?>
<img src="<?php echo esc_url( home_url( '/' ) ); ?>media/oil-icon-pdf.png"></a>
<?php endif; ?>
Kyler Boudreau comments:
Beautiful - worked. Thank you!
Kyle answers:
Try this
<?php if (strpos(get_field('oil_pdf'),'.pdf') !== false): ?>
<img src="<?php echo esc_url( home_url( '/' ) ); ?>media/oil-icon-pdf.png"></a>
<?php endif; ?>