Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active August 29, 2015 14:17
Show Gist options
  • Save obiPlabon/89bc7b8072566b45fc89 to your computer and use it in GitHub Desktop.
Save obiPlabon/89bc7b8072566b45fc89 to your computer and use it in GitHub Desktop.
Created only for my personal reference.
function op_filter_single_page_nav( $atts, $item ) {
if ( ! is_page( get_option( 'page_on_front' ) ) && 'section' == get_post_type( $item->object_id ) ) {
$atts['href'] = home_url() . '#section-' . $item->object_id;
} elseif ( is_page( get_option( 'page_on_front' ) ) && 'section' == get_post_type( $item->object_id ) ) {
$atts['href'] = '#section-' . $item->object_id;
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'op_filter_single_page_nav', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment