Last active
July 22, 2020 19:22
-
-
Save webghostx/eaad55f2de1c99a5ec80ac15fe32e89f to your computer and use it in GitHub Desktop.
Revisions
-
webghostx revised this gist
Jul 22, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ <?php /** * Wordpress Content Filter * Automatisch html-Anker Elemente in Überschriften setzen * * Im ersten Abschnitt (edit bis /edit) können Einstellungen vorgenommen werden. * * @author usysto https://usysto.net/wordpress-content-filter-anker-links-in-ueberschriften-ohne-plugin * @copyright free -
webghostx renamed this gist
Jul 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
webghostx renamed this gist
Jul 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
webghostx revised this gist
Jul 22, 2020 . No changes.There are no files selected for viewing
-
webghostx created this gist
Jul 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ <?php /** * Wordpress Content Filter * Automatisch html-Anker Elemente in überschriften setzen * * Im ersten Abschnitt (edit) können Einstellungen vorgenommen werden. * * @author usysto https://usysto.net/wordpress-content-filter-anker-links-in-ueberschriften-ohne-plugin * @copyright free */ add_filter('the_content', function ($content) { # edit $h_numbers = '2'; // um zB. H2,H3 und H5 zu erwischen, einfach '235' eingeben $insert_link = true; // verlinktes Icon einfügen true/false $link_attr = 'class="h-link"'; // Attribute für den Link setzen $icon_html = '<i class="fa fa-link"></i>'; // html für Icon zB. Font Awesome # /edit $regex = '/(\<h[' . $h_numbers . '](.*?))\>(.*)(<\/h[' . $h_numbers . ']>)/i'; $content = preg_replace_callback( $regex, function ($headings) use ($insert_link, $icon_html, $link_attr) { if (!stripos($headings[0], 'id=')) { $heading_link = ''; $id = sanitize_title(remove_accents($headings[3])); if ($insert_link) $heading_link = '<a href="#' . $id . '" ' . $link_attr . '>' . $icon_html . '</a> '; $headings[0] = $headings[1] . $headings[2] . ' id="' . $id . '">' . $heading_link . $headings[3] . $headings[4]; } return $headings[0]; }, $content ); return $content; }, 9);