Skip to content

Instantly share code, notes, and snippets.

@reformatco
Last active September 11, 2022 10:18
Show Gist options
  • Select an option

  • Save reformatco/2050574 to your computer and use it in GitHub Desktop.

Select an option

Save reformatco/2050574 to your computer and use it in GitHub Desktop.

Revisions

  1. reformatco revised this gist Sep 11, 2022. No changes.
  2. @benpalmer79 benpalmer79 created this gist Mar 16, 2012.
    18 changes: 18 additions & 0 deletions wp-fn-topslug
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function top_slug($post){

    if(count($post->ancestors)>0){
    /* if in a sub section */
    $parent_permalink = get_permalink($post->ancestors[count($post->ancestors)-1]);
    echo basename($parent_permalink);
    }else{
    $permalink = get_permalink($post->ID);
    if($permalink===get_bloginfo('url')."/"){
    /* if on home page */
    return "home";
    }else{
    /* if in a top level section */
    return basename($permalink);
    }
    }

    }