Jump to content

Else/if problem


Certis

Recommended Posts

Hopefully people here know an easy solution to a problem I'm having.

 

First of all, I'm using a script in Wordpress to retrieve the current url. Then I use a code in a link, adding a little code after it, which would switch the theme of my Wordpress (basically, "currenturlcode&wptheme=Sidebar%20disabled").

 

It works great, thanks to that, people will remain on the same page they are and switch the theme. However, if that is clicked on the main page, it goes to the 404 page, cause it needs to use "?" instead of "&" in case of that.

 

So what I need help with here, is somehow making my link see if they are on the main page, and if so, adding "?wptheme=Sidebar%20disabled" there, on other cases"&wptheme=Sidebar%20disabled".

Link to comment
https://forums.phpfreaks.com/topic/209842-elseif-problem/
Share on other sites

Of course.

 

This one is the code that is needed, the "brains" of the url getting, I assume.

 

<?php
function curPageURL() {
$pageURL = 'http';
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;
}
?>

 

 

And this is the link code I use (including with the php url get function.

 

<a href="<?php echo curPageURL(); ?>&wptheme=Sidebar%20disabled">Click here</a>

Link to comment
https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1095361
Share on other sites

Sorry for replying so late, I was dragged to another town by my relatives, and I did not have access to internet there.

 

Unfortunately, that solution does not work, instead, I get this error line:

 

Fatal error: Can't use function return value in write context in /home/certis/domains/certislp.co.cc/public_html/wp-content/themes/atahualpa169/footer.php on line 24

Link to comment
https://forums.phpfreaks.com/topic/209842-elseif-problem/#findComment-1096726
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.