Forums

[resolved] the_title() does not maintain hyphens in url (5 posts)

  1. jungledsales
    Member
    Posted 4 years ago #

    I am trying to attach the post title to a URL but the output URL does not maintain the correct hyphens in between each word.

    <a href="http://www.domain.com/recommends/<?php echo strtolower(get_the_title()); ?>">Visit <?php the_title(); ?></a> | <a href="#review">Submit your review</a>

    Maybe there is a way to save "http://www.domain.com" as a URL and append the title to that URL? I'm stumped. Suggestions?

  2. iridiax
    Member
    Posted 4 years ago #

    Why not use a permalink tag (the_permalink or get_permalink)? Your other option is to use php str_replace.

  3. jungledsales
    Member
    Posted 4 years ago #

    Because the permalink is not the same as my desired URL. The permalink would be http://www.domain.com/post1 and I want the output URL to be http://www.domain.com/recommends/post1

    So I just need a way to grab the post title and append it to a URL. But without losing the hyphens.

    I'll play a little more with str_replace but I don't think that will work.

  4. moshu
    Member
    Posted 4 years ago #

    No, you don't want "the title". You want the "slug"!
    http://wordpress.org/support/topic/128046?replies=8

  5. jungledsales
    Member
    Posted 4 years ago #

    Beautiful! It works. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic