add_anchors( $content );
}
return $content;
}
/**
- Add Links
* Replace headings with an anchor
*/
private function add_anchors( $text ) {
// search for headlines
$pattern = '#]+)?>(.+?)#is';
preg_match_all( $pattern , $text , $headlines, PREG_SET_ORDER);
if( $headlines ){
foreach ($headlines as $headline) {
if ( strlen( $headline[2] ) ) {
$anchor = sanitize_title( $headline[2] );
$icon = '';
$pos = strpos($text, $headline[0]) + 4;
$text = substr_replace($text, $icon, $pos, 0); // inssert after h tag
}
}
}
return $text;
}
}
}
new Add_Anchor_Links();