Title: Use php function in url
Last modified: August 20, 2016

---

# Use php function in url

 *  [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/)
 * I have this code:
 * <div align=”center”><font color=\”#FF00FF\”><?php the_date(‘l – F jS’, ‘<h2>’,‘
   </h2>’); ?></font></div>
 * I would like to put an ‘a href’ around it.

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679540)
 * Something like:
 * `<div class="date"><a href="link_url_goes here"><?php the_date('l - F jS', '<
   h2>', '</h2>'); ?></a></div>`
 * should work. Then style it using CSS – not old HTML 4 markup.
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679543)
 * Thanks for the quick response!
 * I apologize, I didn’t explain myself clearly enough. In the a href I would like
   to have part of the link be a php function. So, for example, I would like `www.
   myquestion.com/<?php the_date?>` so that it will bring up something like`www.
   myquestion.com/2012/04/03`.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679548)
 * `<div class="date"><h2><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?
   php the_date('l - F jS'); ?></a></h2></div>`
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679579)
 * My page breaks when I try to insert a link with a php function in it into the
   loop.
 * Thank you so much for your help. I’ll try to give you another example:
 * Lets say I have this text “My Title”. And I want the link to my title to link
   to the day that the post was made. Following the calendar widget setup, I would
   need to have my link be: [http://www.thenameofmypage.com/year/month/day/](http://www.thenameofmypage.com/year/month/day/)
 * …but that doesn’t work so I’m not sure what to do.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679581)
 * Please post code or markup snippets between backticks or use the code button.
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679586)
 * Sorry about that,
 * `<a href="www.thenameofmypage.com/<?php the_date('Y/m/d/'); ?>"><My Title></a
   >`
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679588)
 * That’s not the code I suggested above…
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679589)
 * Yes, yes I tried the code suggested and my page broke…I don’t know why.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679590)
 * There’s obviously nothing wrong with the code I posted above. Perhaps you added
   it incorrectly?
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679592)
 * When you say `home_url` do you suggest that I put in `www.thenameofmypage.com/
   <?php the_date('Y/m/d/'); ?>` as my home_url. I guess I just don’t understand
   at what point in your code the current date shows up. Does this `( '/' )` bring
   up the date?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679595)
 * > When you say home_url do you suggest that I put in [http://www.thenameofmypage.com/&lt](http://www.thenameofmypage.com/&lt);?
   > php the_date(‘Y/m/d/’); ?> as my home_url.
 * No. Just use `<?php echo esc_url( home_url( '/' ) ); ?>">`
 *  Thread Starter [dml3001](https://wordpress.org/support/users/dml3001/)
 * (@dml3001)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679599)
 * Ok. It seems I might have copied it wrong the first time. Now, it doesn’t break,
   but the link that shows up is a link to the home page and not a link to the home
   page with `/Y/m/d/` at the end. If I am not explaining myself well enough, then
   I won’t take up any more of your time, but thank you for your help so far.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Use php function in url’ is closed to new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 2 participants
 * Last reply from: [dml3001](https://wordpress.org/support/users/dml3001/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/use-in-url/#post-2679599)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
