WordPress.org

Ready to get started?Download WordPress

Forums

Better Anchor Links
[resolved] Nicer looking anchor names (3 posts)

  1. jesperf
    Member
    Posted 2 years ago #

    With international characters in the header tags, the anchor names end up a real mess:

    <h3>Område 1</h3> becomes #Omr%C3%A5de+1

    if you add a function to clean the characters before you print them, for example like this:

    function toAscii($str, $replace=array(), $delimiter='-') {
    			if( !empty($replace) ) {
    				$str = str_replace((array)$replace, ' ', $str);
    			}
    
    			$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    			$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
    			$clean = strtolower(trim($clean, '-'));
    			$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
    
    			return $clean;
    		}

    (from http://cubiq.org/the-perfect-php-clean-url-generator)

    and then calling it in the proper places, for example replacing

    $rtext='<a name="'.urlencode(strip_tags($val[2])).'"></a>';

    with

    $rtext='<a name="'.urlencode($this->toAscii(strip_tags($val[2]))).'"></a>';

    you end up with the anchor name #omrade-1 instead. Much better in my view.

    http://wordpress.org/extend/plugins/better-anchor-links/

  2. elpresidento
    Member
    Plugin Author

    Posted 2 years ago #

    With locale it looks working. Thanks jesperf I added to 1.5.3. Please test it.

  3. elpresidento
    Member
    Plugin Author

    Posted 2 years ago #

    In some sites it doesnt work. It is solved in version 1.5.4

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic