0
I have this php function that takes the current url:
<?php
function UrlAtual(){
$dominio= $_SERVER['HTTP_HOST'];
$url = "http://" . $dominio. $_SERVER['REQUEST_URI'];
return $url;
}
?>
I would like to use this current url <?php echo UrlAtual(); ?>
in an image. I tried the following bad way did not work:
<a href="<?php echo UrlAtual(); ?>" target="_blank" rel="nofollow"><img src="https://3.bp.blogspot.com/-qoDmQ9q_4VI/WAoI-hJPlxI/AAAAAAAAALI/V9C0JhIDuW8SQ4JQwa6NXaLo_PE4CWwDQCLcB/s1600/02.png" width="250px"/></a>
insira o código aqui
What appears inside the href?
– JuniorNunes
I use Wordpress, and when I put the code this way ai simply gives error and does not load the page, it was to appear this image ai https:/3.bp.blogspot.com/-qoDmQ9q_4VI/Waoi-hJPlxI/AAAAAAALI/V9c0jhiduw8sq4jqwa6nxalo_pe4cwwdqclcb/s1600/02.png with the function link...
– Guajenet
but what error does it make? you can see in the log?
– JuniorNunes
The error is that the area where the code is located does not appear, in the case of "single.php" and not even the image, and if I put a normal address in place of <?php echo Urlatual(); ? > ai charge normal
– Guajenet
So, this is actually being caused by the error, read here to see how you can detect errors in PHP, to find out exactly what’s happening: https:/easypiewp.com/wordpress-error-log-your-friend/
– JuniorNunes
But is this code correct? Would it be like this insertion of this php function inside href? I thought tbm to use the following: <php <a href=" echo Urlatual();" target="_Blank" rel="nofollow"><img src="https://3.bp.blogspot.com/-qoDmQ9q_4VI/Waoi-hJPlxI/AAAAAAALI/V9c0jhiduw8sq4jqwa6nxalo_pe4cwqwdclcb/02.png" width="250px"/></a> ? > Would be correct?
– Guajenet
The way you put it is correct, but maybe he is not finding this function for example, or some error in the function, to know exactly what the problem is, we should take a look at the error log, you know? Do the following, go to your function, comment everything and put a: Return 'test';
– JuniorNunes
I did the test and its function is correct. The problem is probably that this function is not in the same file that you are calling it. Or this function is inside a class, so you need to initialize the class to then call the function.
– Andrei Coelho