• Resolved sligowaths

    (@sligowaths)


    Hi,

    I′m designing a new theme and I need to know the current post slug(post name sanitized), so I can make a different header image for each Page.

    For example, I have a page called “iPod Nano” and I need a function that returns “ipod-nano”.

    I′ve searched for this on Codex, Google, functions.php, etc and I didn′t find anything nice. I only found this $posts[0]->post_name; but its too “dirty”

    Any ideas and/or different approach will be greatly aprreciated. Thanks in advance, and sorry my bad English.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Its a bit unclear if you mean Post or Page.
    In WordPress parlance there are pages and Pages.
    Pages with a capital P are the ones you write under Write Pages and they can have different templates associated to them. The Codex doc on Pages describes this.

    There is no ‘the_slug’ function in WordPress like there is for the_title, the_content, etc.

    Thread Starter sligowaths

    (@sligowaths)

    Hi, thanks for your reply!! I mean Page with capital P

    What do you suggest? Create “the_slug” function and place together the others “the_*”?

    Thanks again,
    Tiago

    Thread Starter sligowaths

    (@sligowaths)

    I created this function and placed in template-functions.php. Seems to work fine for me. Thanks for all.

    function get_the_slug() {

    global $post;

    if ( is_single() || is_page() ) {
    return $post->post_name;
    }
    else {
    return "";
    }

    }

    I think in WP 2.x you can have your own functions for a theme (see the default, it has a file functions.php) which means you could try NOT to modify core files.
    I am not a coder, so don’t ask me how to do it, but I always have these “big ideas” ??

    Thread Starter sligowaths

    (@sligowaths)

    Moshu,

    You′re right! If I keep the function in a core file, one future WP update may break my blog.

    Thanks for the tip!

    This is really good info!
    Thanks guys!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to get the current post slug?’ is closed to new replies.