Skip to content

Instantly share code, notes, and snippets.

@izzygld
Created June 7, 2021 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izzygld/5da9606343b9e55e80a90a52e2a77e32 to your computer and use it in GitHub Desktop.
Save izzygld/5da9606343b9e55e80a90a52e2a77e32 to your computer and use it in GitHub Desktop.
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