Support

Account

Home Forums General Issues Strip whitespace from custom field

Solved

Strip whitespace from custom field

  • Hi I’m trying to strip whitespaces from a telephone custom field (from options page) in order to set up the telephone number as a telephone link. I’ve tried this but no joy:

      <a href="tel:<?php str_replace(the_field('box_office', 'option'));  ?>" title="Phone our office"><?php the_field('general_info', 'option'); ?></a>
    

    Any help much appreciated.
    Charlie

  • Hi @ladygeekgeek

    There are a few this missing with your above code:
    1. You need to echo the str_replace returned value
    2. Please use get_field instead of the_field when returning data to a function
    3. Please use the $find and $replace parameters in the str_replace function.

    Your code should look more like this:

    
    <?php echo str_replace(' ', '', get_field('box_office', 'option')); ?>
    

    Thanks
    E

  • You are a Star! It works perfectly and I feel like an idiot for leaving out the echo 🙂

    Thanks a million
    C

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Strip whitespace from custom field’ is closed to new replies.