Skip to content

Instantly share code, notes, and snippets.

@evanrose
Last active May 29, 2019 19:03
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 evanrose/eb5e69148aa9f00489783f237edc286c to your computer and use it in GitHub Desktop.
Save evanrose/eb5e69148aa9f00489783f237edc286c to your computer and use it in GitHub Desktop.
Link ID
//id="<?php echo er_link_id( 'top nav', $linkText );"
function er_link_id( $location, $link_text ) {
global $post;
if( $post->post_parent ) {
$post_parent = get_post_field( 'post_name', $post->post_parent ) . '-';
}
$post_slug = $post->post_name;
$link_id = $post_parent . $post_slug . '-' . sanitize_title( $location ) . '-' . sanitize_title( $link_text );
return $link_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment