WordPress.org

Ready to get started?Download WordPress

Forums

Get the current URL (6 posts)

  1. rubencdl
    Member
    Posted 6 years 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 6 years 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 6 years ago #

    Thanks, the correct code is:

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

  4. microkid
    Member
    Posted 6 years ago #

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

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

  5. fatcat718
    Member
    Posted 5 years ago #

    If you are trying to detect if a user is viewing the home page, you can use is_home(), which is a WordPress specific function. In a conditional statement it would be used like this:

    if(is_home()){
    // code for home page goes here
    }

    I use this on my blog http://www.fatcatreport.com. If you look at the home page, I have an about us box on the right side. On all the other pages, I hide the box and display Google Ads.

    You can use one of the following for other pages too:

    is_category() - Use this if you want to detect if a user is viewing a category page. Or if you want to detect a specific category you can use something like is_category('SEO Tips') for a category called 'SEO Tips'.

    is_single() - If user is viewing a post page. For a specific post use is_single(17) for a post with an id of 17. Or you can use is_single('Wordpress Tips') of a post with the title 'Wordpress Tips'.

    Here is a complete list of conditional tags here: http://codex.wordpress.org/Conditional_Tags

  6. roya khosravi
    Member
    Posted 5 years ago #

    try : <?php the_guid($id); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags