WordPress: Get Page ID (Function)


/ Published in: PHP
Save to your folder(s)

This custom function is useful if you want to get the ID of a page.


Copy this code and paste it in your HTML
  1. function get_page_id($page_name) {
  2. global $wpdb;
  3. $page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
  4. return $page_name; }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.