Home Forums General Issues Echo 'clean' acf field that strips all spaces and special characters


Echo 'clean' acf field that strips all spaces and special characters

  • Hi,

    I’m trying to add a css id to an element that is the same as the value it is given, but stripped from all spaces and special characters.
    So for example if I have a field with a value of “*Title& example” I want it to output something like this: <h3 id=”1-title-example”>Title example</h3>

    Normally this would be simply done by something like this:
    <h3 id" <?php the_field('title'); ?> "><?php the_field>('title'); ?></h3>

    But of course that doesn’t work with outputting clean values (without spaces, etc.).

    Is this possible?

  • Alright, got this fixed myself with using sanitise_title_for_query.
    With some great help from:

    <h3 id="<?php $page_link = sanitize_title_for_query( get_field('title') ); echo esc_attr( $page_link ); ?>"><?php the_field('title');?></h3>

  • Hey @ardblok, thanks for that, however I am unable to strip the accents (French lang) off the field. It looks like this “marquage-int%c3%a9rieur” any ideas on how to clean this? ๐Ÿ™‚


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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.