Created
January 25, 2014 20:11
-
-
Save tarikcayir/8622794 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
/** | |
* Content heading auto ID | |
* | |
* Examples; | |
* <h*>Test Header</h*> | |
* <h* id="test-header">Test Header</h*> | |
*/ | |
add_filter( 'the_content', 'content_heading_filter' ); | |
function content_heading_filter( $content ) { | |
return $content = preg_replace_callback("#<(h[1-6])>(.*?)</\\1>#", "re_title", $content); | |
} | |
function re_title($match) { | |
list($_unused, $h2, $title) = $match; | |
$id = sanitize_title($title); | |
return "<$h2 id='$id'>$title</$h2>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment