[resolved] How can I go about stripping non-ASCII characters from permalinks? (5 posts)

  1. virtuexru
    Posted 6 years ago #

    I'm trying to create a plugin to not allow any weird characters into the permalink such as ®, ©, ™, ∞, &, etc...

    I did a filter onto the 'editable_slug' and while this works for display purposes (the weird characters get filtered out), even though it might not show up in display, it is still being passed through when I update a post.

    Anyone know how to actually make sure the data is passed AFTER I have cleaned it up? Or any idea on how I would go about doing this? Thank you!

    Here is my plugin for reference:

    if( !function_exists( 'strip_weird_permalink' ) )
    	function strip_weird_permalink($post_id)
    		$output = $post_id;
    		// strips all *non-ascii* characters
        		$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
        		return $output;
    	add_filter('editable_slug', 'strip_weird_permalink', 10, 1);
  2. virtuexru
    Posted 6 years ago #

    Should I be filtering post_link instead? How can I denote whether or not the user is in an administration page? I just want to filter out non-ASCII characters when editing the permalink on the backend.

  3. virtuexru
    Posted 6 years ago #

    Any ideas? Thanks in advance!

  4. virtuexru
    Posted 6 years ago #

    Found a fix, have to hook into the sanitize_title to clean the permalink up.

    add_action('sanitize_title', 'strip_weird_permalink', 1, 1);
  5. Faisal Humayun
    Posted 5 years ago #

    I'd really appreciate knowing how you went about implementing this in your blog -- is there a plugin you created?
    At the present time, a number of old post titles have » in them and are truly messing up url shortening and editing.
    Much thanks,

Topic Closed

This topic has been closed to new replies.

About this Topic