Forums

alter the_permalink() output (4 posts)

  1. mexsillus
    Member
    Posted 11 months ago #

    I would like to add something additional at the end of the link when generating the html. (I am reviewing flash games, and would like to create a page with the actual game on a page with similar URL. So example.com/bloons would review the game, and example.com/game-bloons would be a page to play the game.)

    this is the effect I am going for, even though this code doesn't work:

    <a href="<?php str_replace(".com/", ".com/game-", the_permalink()) ?>">link</a>

    i tired turning the_permalink() into a string but I can't seem to do that. (I am very new to php and wordpress and programming in general). Any ideas on how to accomplish this?

  2. chaoskaizer
    Member
    Posted 11 months ago #

    The the_permalink() function will print the output before you can perform anything so try uses get_permalink() function instead.

    str_replace(".com/", ".com/game-", get_permalink($post->ID));
  3. mexsillus
    Member
    Posted 11 months ago #

    AWESOME, thank you chaoskaizer, that did it.

    here is the final code for anyone wondering:

    <?php $urlVar = str_replace(".com/", ".com/game-", get_permalink($post->ID))?>
    <a href="<?php echo $urlVar ?>" rel="bookmark">play</a>
  4. FMacastro
    Member
    Posted 2 weeks ago #

    I had a similar problem and this post helped me fixing it.

    Thanks!

    MAC :)

Reply

You must log in to post.

About this Topic