WordPress get parent slug

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

This is a really short function you can use inside The Loop to get the parent page slug (useful to add to the body classes or something)

Copy this code and paste it in your HTML
  1. function get_parent_slug(){
  2. $parent = get_page($post->post_parent);
  3. return $parent->post_name;
  4. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.