Is it possible to echo a page path suffix only? ie: if the path/permalink is example.com/about, echo just "about"?

My page paths are different than my page titles (ie: page title for example.com/about is "About ACME Co.") so I cannot use the_title()

I am trying to echo just the suffix so it is the same name as an icon image for each page, so if the page is "about", the icon is icon_page-about.png, like this (wpse_page_suffix is where I need the help):

<img src="<?php bloginfo('template_directory'); ?>/_img/icon_page-<?php wpse_page_suffix();?>.png" alt="Icon - <?php the_title();?>" />


Use the Post Object instead.

When in the loop, do this:

global $post;
echo $post->post_name;

That should do the trick.

  • Interesting. Looks like it works to use just echo $post->post_name;, like this: <img src="<?php bloginfo('template_directory'); ?>/_img/icon_page-<?php echo $post->post_name;?>.png" alt="Icon - <?php the_title();?>" /> – codeview Jul 15 '14 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.