• Resolved virtuexru

    (@virtuexru)


    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);
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter virtuexru

    (@virtuexru)

    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.

    Thread Starter virtuexru

    (@virtuexru)

    Any ideas? Thanks in advance!

    Thread Starter virtuexru

    (@virtuexru)

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

    add_action('sanitize_title', 'strip_weird_permalink', 1, 1);

    Hi,
    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,
    Faisal

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I go about stripping non-ASCII characters from permalinks?’ is closed to new replies.