[Plugin: Better Anchor Links] Nicer looking anchor names
-
With international characters in the header tags, the anchor names end up a real mess:
<h3>Omr?de 1</h3>
becomes #Omr%C3%A5de+1if 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 https://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.
https://www.ads-software.com/extend/plugins/better-anchor-links/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘[Plugin: Better Anchor Links] Nicer looking anchor names’ is closed to new replies.