Forums

Get the current URL (4 posts)

  1. rubencdl
    Member
    Posted 1 month ago #

    Hi guys.
    I need to know what is the function that returns the current URL. I used get_permalink() but this don't work with the main page, the categories page, search... and other pages, only works for the posts pages.

    Thanks.

  2. Pinoy.ca
    Member
    Posted 1 month ago #

    <?php echo $_SERVER['PHP_SELF'] ?>

    If you want something else, then google "php get current url" to find the code snippet you need.

  3. rubencdl
    Member
    Posted 1 month ago #

    Thanks, the correct code is:

    <?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>

  4. microkid
    Member
    Posted 1 month ago #

    You can use get_permalink() outside the loop with an ID as a parameter:

    <?php echo get_permalink( $post->ID ); ?>

Reply

You must log in to post.

About this Topic

Tags