How to remove special characters in post title

Please guys

I need help on how to remove special characters in POST TITLE -

Certain SYMBOLS LIKE { }

Please Note: I am a beginner coder, kindly make the solution very simple for me to understand

Topic characters posts Wordpress

Category Web


You can use WordPress function wp_strip_all_tags()

$args = array(
    'post_type' => 'post',
    'post_title'    => wp_strip_all_tags( $string ),
  );

Or you can also use preg_replace() :

preg_replace('/[^A-Za-z0-9\-]/', '', $string);

You can use function:

sanitize_title( string $title, string $fallback_title = '', string $context = 'save' );

More info: https://developer.wordpress.org/reference/functions/sanitize_title/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.