• Resolved Ashkan

    (@3tayesh)


    Hi, I deleted the Replace Zero Width Non-joiner from the title with the following code, but it does not apply to the content address.
    How do I change the Replace Zero Width Non-joiner with -?

    function add_to_page_titles($title)
    {
    
        $title = str_replace("\xE2\x80\x8C", " ", $title);
        return $title;
    }
    add_filter('the_title', 'add_to_page_titles');
    add_filter('wpseo_title', 'add_to_page_titles');
    Title:
    ????? ????? ?? ???? ?? ???? ????? ? ??????????????? ????? ????? ????????
    Convert to:
    ????? ????? ?? ???? ?? ???? ????? ? ?????? ?????? ? ????? ????? ?? ?????
    ----------------
    Content URL:
    ?????-????-??-????-??-????-?????-?-?????????????-?????-?????-???????
    Become:
    ?????-????-??-????-??-????-?????-?-??????-??????-?-?????-?????-???????
    The goal is to replace the Replace Zero Width Non -joiner character with - in the slug address.
    
    https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128&utf8=string-literal
    Zero Width Non-joiner
    \xe2\x80\x8c
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @3tayesh,

    If you would like to filter the default permalinks generated with Permalink Manager you will need one more snippet:

    function pm_filter_default_post_uris($default_uri, $native_slug, $post, $slug, $native_uri) {
    	$default_uri = str_replace("\xE2\x80\x8C", "-", $default_uri);
    
    	return trim($default_uri, "/");
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_filter_default_post_uris', 10, 5);

    You can also filter the output of native function that is used to generate the slug from the title when the post is created:
    add_filter('sanitize_title', 'add_to_page_titles');

    Thread Starter Ashkan

    (@3tayesh)

    Hello, thank you
    The code you entered does not work
    https://s4.uupload.ir/files/tra_g746.jpg

    Final code

    function add_to_page_titles($title)
    {
    
        $title = str_replace("\xE2\x80\x8C", " ", $title);
        return $title;
    }
    add_filter('the_content', 'add_to_page_titles');
    add_filter('the_excerpt', 'add_to_page_titles');
    add_filter('the_title', 'add_to_page_titles');
    add_filter('wpseo_title', 'add_to_page_titles');
    add_filter('sanitize_title', 'add_to_page_titles');
    
    function pm_filter_default_post_uris($default_uri, $native_slug, $post, $slug, $native_uri) {
    	$default_uri = str_replace("\xE2\x80\x8C", "-", $default_uri);
    
    	return trim($default_uri, "/");
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_filter_default_post_uris', 10, 5);

    Please provide a code to support the Zero Width Non -joiner character and remove it from the address
    https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128&utf8=string-literal

    Plugin Author Maciej Bis

    (@mbis)

    Hi @3tayesh,

    Please replace the last function with this code:

    function pm_filter_default_post_uri($full_slug, $post, $post_name) {
    	if(strpos($post->post_title, "\xE2\x80\x8C") !== false) {
    		$new_slug = str_replace("\xE2\x80\x8C", "-", $post->post_title);
    	}
    
    	return (!empty($new_slug)) ? $new_slug : trim($full_slug, "/");
    }
    add_filter('permalink_manager_filter_default_post_slug', 'pm_filter_default_post_uri', 10, 3);

    Then, to use it you will need to use “Regenerate/reset” functionality:
    https://permalinkmanager.pro/docs/basics/how-to-regenerate-the-custom-permalinks/

    Unfortunately, WordPress automatically removes the Zero Width Non-joiner character from the slug when it is generated and sanitized. If this does not not help, I will not be able to provide you with another solution :/

    Thread Starter Ashkan

    (@3tayesh)

    Thank you very much, the problem is solved.
    Please help me solve this problem as well
    
    function replace_words($string)
    {
        $persian = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?'];
        $arabic = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?'];
    
        $num = range(0, 9);
        $convertedPersianNums = str_replace($persian, $num, $string);
        $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);
    
        return $englishNumbersOnly;
    }

    https://s4.uupload.ir/files/tra_66ey.jpg

    • This reply was modified 3 years, 1 month ago by Ashkan.
    Plugin Author Maciej Bis

    (@mbis)

    Hi @3tayesh,

    Generally, I do not provide any customization service. I will make one last exception here.

    You can simply use your function inside the snippet I sent you:

    function pm_filter_default_post_uri($full_slug, $post, $post_name) {
    	$post_title = replace_words($post->post_title);
    	
    	if(strpos($post->post_title, "\xE2\x80\x8C") !== false) {
    		$new_slug = str_replace("\xE2\x80\x8C", "-", $post_title);
    	}
    
    	return (!empty($new_slug)) ? $new_slug : trim($full_slug, "/");
    }
    add_filter('permalink_manager_filter_default_post_slug', 'pm_filter_default_post_uri', 10, 3);
    Thread Starter Ashkan

    (@3tayesh)

    Hello Brother
    Sorry to bother you
    Unfortunately, the code for converting Persian numbers to English did not work for the postal address

    Convert Persian/Arabic Numbers To English Numbers

    function replace_words($string) {
        $persian = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?'];
        $arabic = ['?', '?', '?', '?', '?', '?', '?', '?', '?','?'];
    
        $num = range(0, 9);
        $convertedPersianNums = str_replace($persian, $num, $string);
        $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);
    
        return $englishNumbersOnly;
    }
    add_filter('the_content', 'replace_words');
    add_filter('the_excerpt', 'replace_words');
    add_filter('the_title', 'replace_words');
    add_filter('wpseo_title', 'replace_words');
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change Zero Width Non-joiner character with – in slug’ is closed to new replies.