Hi there,

I am trying to have a PHP variable in my link, so that my final link would look like:


I've managed to get example.com/variable-goes-here but no more than that. I really don't know PHP very well, so help would be greatly appreciated. Please excuse my beginner level. Thanks! :D

<?php $eformat = $post–>post_name; echo "<a href=\"$eformat\">Download this blog post in eFormat (.rtf)</a>" ?>
6 Years
Discussion Span
Last Post by Feabionsu

echo "<a href='".$eformat."'>Download this blog post in eFormat (.rtf)</a>";

Edited by muralikalpana: n/a


Well, I've tried your code within my code, but all it gives me is www.example.com/eformat/.rtf

What to do? =(

<?php $eformat = $post–>post_name; echo "<a href='".$eformat.".rtf'>Download this blog post in eFormat (.rtf)</a>" ?>

i was tested. its working fine. once check echo $eformet;
<?php $eformat = "test"; echo "<a href='".$eformat.".rtf'>Download this blog post in eFormat (.rtf)</a>" ?>


@Kalpana: You are right, it works when the variable is just a text like "test"... but I want to use a Wordpress variable, namely $post->post_name which should give me the slug of any blog post.

@Shanti: What slash are we talking about? Are you saying that the post slug automatically includes a trailing slash, which is why it doesn't work? If so, do you know of a way to fix that or of an alternative Wordpress variable?


Wow, two solutions have been found on two other forums. :) And here I was trying to figure out even one solution by myself.

<?php echo "<a href='eformat/{$post->post_name}.rtf'>Download this blog post in eFormat (.rtf)</a>" ?>
<?php $var = $post->post_name; echo '<a href="eformat/' . $var . '.rtf">Download this blog post in eFormat (.rtf)</a>'; ?>

Thanks everyone for your help!

Edited by Feabionsu: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.