WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Insert the slug in a template? (7 posts)

  1. mbalara
    Member
    Posted 7 years ago #

    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?

  2. moshu
    Member
    Posted 7 years ago #

    I am not a coder - just a diligent reader of the Codex. Maybe this helps?
    http://codex.wordpress.org/Template_Tags/get_permalink

  3. mbalara
    Member
    Posted 7 years ago #

    Nope, not exactly. I don't need the permalink, e.g. http://www.mysite.com/about-the-birds-on-the-roof/, I only need the slug, e.g. about-the-birds-on-the-roof.

  4. moshu
    Member
    Posted 7 years ago #

    I assumed you searched. I often fall into this mistake - assuming more than people are willing to do to solve their own problems...
    http://wordpress.org/search/return+the+slug?forums=1

  5. mbalara
    Member
    Posted 7 years ago #

    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.

  6. elmichos
    Member
    Posted 7 years ago #

    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?

  7. elmichos
    Member
    Posted 7 years ago #

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

    Heh.

Topic Closed

This topic has been closed to new replies.

About this Topic