diff --git a/functions.php b/functions.php index b1d3f9a..059f5cf 100644 --- a/functions.php +++ b/functions.php @@ -230,3 +230,22 @@ function redirect_private_pages_to_join_page() { } add_action( 'template_redirect', __NAMESPACE__ . '\\redirect_private_pages_to_join_page' ); + +/** + * Add id attribute to

,

,

,

,

tags + * + * @param string $content Content of the current post. + * + * @return string $content The filtered post content. + */ +function anchor_content_headings( $content ) { + $content = preg_replace_callback( "/\(.*?)\<\/h([1|2|3|4|5])\>/", function ( $matches ) { + $hTag = $matches[1]; + $title = $matches[2]; + $slug = sanitize_title_with_dashes( $title ); + return '' . $title . ''; + }, $content ); + + return $content; +} + add_filter( 'the_content', __NAMESPACE__ . '\\anchor_content_headings' );