Created
June 7, 2021 07:34
-
-
Save izzygld/5da9606343b9e55e80a90a52e2a77e32 to your computer and use it in GitHub Desktop.
This file contains 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
add_filter( 'the_content', 'airpets_terms_nav' ); | |
function airpets_terms_nav($content) { | |
if( is_page_template( 'page-terms.php' ) ): | |
$menu = '<div id="top" class="anchor-menu"><ul class="menu">'; | |
$blocks_arr = parse_blocks( get_the_content() ); | |
foreach( $blocks_arr as $block ): | |
$text = strip_tags( $block['innerHTML'] ); | |
$slug = slugify( $text ); | |
foreach( $block as $key => $value ): | |
if( $key == 'blockName' && $value == 'core/heading' ) $menu .= '<li><a class="btn" href="#' . $slug . '">' . $text . '</a></li>'; | |
endforeach; | |
endforeach; | |
$menu .= '</ul></div>'; | |
$content = $menu . $content; | |
endif; | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment