Forums

[resolved] Current Page URL (4 posts)

  1. Nasir Zia
    Member
    Posted 6 months ago #

    hi,
    How can i get the url of current page to be stored in a variable.
    I tried this,

    echo get_permalink($ID);
    and
    the_permalink()
    But that doesn't work with a blog page layout...

    P.S I want the url to be stored in a variable like this.
    http://www.mysite.com/blog

  2. David Gwyer
    Member
    Posted 6 months ago #

    Try this function, it has worked pretty well for me:

    function current_page_url() {
    	$pageURL = 'http';
    	if( isset($_SERVER["HTTPS"]) ) {
    		if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    	}
    	$pageURL .= "://";
    	if ($_SERVER["SERVER_PORT"] != "80") {
    		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    	} else {
    		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    	}
    	return $pageURL;
    }
  3. Nasir Zia
    Member
    Posted 6 months ago #

    Gave some Parse Error :'(

  4. erikaslt
    Member
    Posted 5 months ago #

    Thanks, David Gwyer,

    it worked great for me :) i added your function to themes/my_theme/functions.php

    and then used in header.php like this:
    <?php echo current_page_url(); ?>

Reply

You must log in to post.

About this Topic