Support » Fixing WordPress » Insert the slug in a template?

  • Resolved mbalara


    Hi helpful WP gods. I’ve got a problem.

    I need to use the slug in a template, but so far I can’t find any template tag which will return the slug. Is there one? A plugin? A trick? Secret-handshake?

    More specifically, I’m making an image for each post. This image will have the slug as it’s name, e.g. “about-the-birds-on-the-roof.gif” If I could suck the slug into the template, I’d be able to reference these images automatically, and not have to fool with the cumbersome upload interface and HTML copying in WP.

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I am not a coder – just a diligent reader of the Codex. Maybe this helps?

    Nope, not exactly. I don’t need the permalink, e.g., I only need the slug, e.g. about-the-birds-on-the-roof.

    I assumed you searched. I often fall into this mistake – assuming more than people are willing to do to solve their own problems…

    Thanks for the help, but also for the charming sarcasm. Assuming I searched was correct. Assuming I searched exactly for “return the slug” would however be false. Try searching for only “the slug” and see how many of the useful posts from your search turn up on the first results page.

    I’m trying to do exactly the same thing as mbalara. I haven’t found anything helpful in the forums though. The closest template tag to what I need is <?php permalink_anchor('title'); ?>. That tag doesn’t echo the post slug – only an anchor (obviously). But since the slug is returned in the html code as <a id=”post-slug”></a> I think this widely spread problem must have a solution…

    PS: <?php echo $post->post_name; ?> doesn’t seem to work.

    Anyone? Please?

    “Sure enough, you post something and then figure it out 5 minutes later.”


Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Insert the slug in a template?’ is closed to new replies.