WordPress.org

Support

Support » How-To and Troubleshooting » Retrieve non-permalink sanitized title

Retrieve non-permalink sanitized title

  • I’m trying to retrieve the sanitized title (“my-first-sony”) for use as an anchor. Does anyone know the php function for this? I tried digging through the the_permalink and the_title functions but I couldn’t seem to figure it out. Can anyone help me out?

Viewing 8 replies - 1 through 8 (of 8 total)
  • James Huff
    Support Team Rep.

    @macmanx

    I’m sorry, could you describe this a bit more? If you’re just trying to link to a post, then just link to that post’s URL.

    I’m currently adapting WP for use in managing a corporate website like a CMS. The blog-like functionality will be used to post company news. However, I’ve set it up so that there won’t be any way to access individual posts so the news will only exist as a listing or news archive. At the same time, I want the X most recent posts to appear as excerpts on the front page of this website.
    My dilemma is that I want to link excerpts on the front page to posts in the news section but if I use permalinks, it will open up individual posts rather than just jump to a post in an archive. My solution is to provide a link to an archive with a # anchor.
    So I want an excerpt on the front page with the title “Stocks are up” to generate a “read more >>” link that points to /2004/12/#stocks-are-up. That URL+anchor will open up a Dec 2004 archive and jump to the full news post. To do that, I need a way to get the sanitized title (with hyphens) to form the anchor in the link.
    I’ve taken a look at the the_permalink function code but it seems to use a SQL query to retrieve the title and I don’t know how to work with that within WP.

    That was it. Thanks Kafkaesqui.

    korereactor
    Member

    @korereactor

    Does anyone know of an answer for this one? What was “it”? A solution would be very helpful on this one!

    korereactor
    Member

    @korereactor

    Anyone?

    No template tag for this, so you have to grab it from the $post array:

    <?php echo $post->post_name; ?>

    (Looks like another of those old “disappearing post'” threads.)

    korereactor
    Member

    @korereactor

    Thanks!

    I was also looking for this variable so I could call page header images named in the same format. Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Retrieve non-permalink sanitized title’ is closed to new replies.