You are viewing an old revision of this post, from June 26, 2013 @ 01:25:00. See below for differences between this version and the current revision.

How To Get the URL of the page you are on with PHP

Wisdom taken from here: http://wordpress.org/support/topic/how-to-get-the-url-of-the-page-you-are-on-with-php [php] echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; [/php] If you are in the WordPress loop: Yes it will work for lists of posts, providing they use a regular loop.. the_permalink() is a loop function, it's made for use "in the loop". If you have a non-standard loop, you can just as easily use... echo get_permalink($ID); where $ID is a variable where you're storing the ID for the "current" page/post in your custom loop or you can again use this with a single entry, just as long as you pass the ID into the fucntion.

Revisions

Revision Differences

June 26, 2013 @ 01:25:00Current Revision
Content
Unchanged: Wisdom taken from here: <a href="http:// wordpress.org/ support/topic/ how-to-get-the-url-of-the- page-you-are- on-with-php" target="_blank" >http://wordpress.org/support/ topic/how-to- get-the-url- of-the-page-you- are-on-with-php</a>Unchanged: Wisdom taken from here: <a href="http:// wordpress.org/ support/topic/ how-to-get-the-url-of-the- page-you-are- on-with-php" target="_blank" >http://wordpress.org/support/ topic/how-to- get-the-url- of-the-page-you- are-on-with-php</a>
Unchanged: [php]Unchanged: [php]
Deleted: &amp;lt;pre&amp; gt;&amp;lt;code&amp;gt;echo &amp;quot;http: //&amp;quot; . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_ URI'];&amp;lt; /code&amp;gt; &amp;lt;/pre&amp;gt; Added: echo &quot;http://&quot; . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
Unchanged: [/php]Unchanged: [/php]
Unchanged: If you are in the WordPress loop:Unchanged: If you are in the WordPress loop:
Unchanged: Yes it will work for lists of posts, providing they use a regular loop..Unchanged: Yes it will work for lists of posts, providing they use a regular loop..
Unchanged: <code>the_permalink( )</code> is a loop function, it's made for use "in the loop".Unchanged: <code>the_permalink( )</code> is a loop function, it's made for use "in the loop".
Unchanged: If you have a non-standard loop, you can just as easily use...Unchanged: If you have a non-standard loop, you can just as easily use...
Unchanged: <code>echo get_permalink( $ID);</code> where $ID is a variable where you're storing the ID for the "current" page/post in your custom loop or you can again use this with a single entry, just as long as you pass the ID into the fucntion.Unchanged: <code>echo get_permalink( $ID);</code> where $ID is a variable where you're storing the ID for the "current" page/post in your custom loop or you can again use this with a single entry, just as long as you pass the ID into the fucntion.

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: , , ,

No comments yet.

Leave a Reply