• Resolved mbalara

    (@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?
    https://codex.www.ads-software.com/Template_Tags/get_permalink

    Thread Starter mbalara

    (@mbalara)

    Nope, not exactly. I don’t need the permalink, e.g. https://www.mysite.com/about-the-birds-on-the-roof/, 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…
    https://www.ads-software.com/search/return+the+slug?forums=1

    Thread Starter mbalara

    (@mbalara)

    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.”

    Heh.

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