Skip to content

Instantly share code, notes, and snippets.

@lcdsantos
Forked from davidpaulsson/wp-get_id_by_slug
Created February 1, 2017 13:57
Show Gist options
  • Select an option

  • Save lcdsantos/b25d21a0afb85bd89a41fc48afb6b609 to your computer and use it in GitHub Desktop.

Select an option

Save lcdsantos/b25d21a0afb85bd89a41fc48afb6b609 to your computer and use it in GitHub Desktop.

Revisions

  1. @davidpaulsson davidpaulsson created this gist Feb 26, 2014.
    11 changes: 11 additions & 0 deletions wp-get_id_by_slug
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // Usage:
    // get_id_by_slug('any-page-slug');

    function get_id_by_slug($page_slug) {
    $page = get_page_by_path($page_slug);
    if ($page) {
    return $page->ID;
    } else {
    return null;
    }
    }