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:
http://zoerooney.com/blog/web-development/custom-fields-flexible-layouts/
<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? 🙂
Thanks!