• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

QUESTION Get Page URL in HTML

Messages
3
Likes
0
Points
1
#1
Hi

I've added an HTML snippet set to Automatic Insertion, Insert After Post, Page equals All Posts.

This works really well, however in my HTML I need the path to the current post e.g either https://www.hiretracknx.com:443/rental-equipment-return-on-investment/ or /rental-equipment-return-on-investment/

I think I can do this with attributes, but I was wondering if there is anyway to set the attribute automatically, rather than me having to manually set it for each post ?
 
Messages
3
Likes
0
Points
1
#2
actually I just realised I can't use attributes as the snippet is added to the post automatically, so there's nowhere to create the attribute
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#3
Hello.

This question is more about PHP than about the plugin.
You need to use a universal snippet, since PHP code can be used in it.

To get the current URL, use this code
PHP:
$url = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $url;
 
Messages
3
Likes
0
Points
1
#4
Can you explain a little more please. I don't seem to have any samples that demonstrate using PHP & HTML together in a universal snippet and the documentation doesn't detail either.
Do I create one universal snippet or two snippets, one for the php & one for the HTML ?
If I create one, how does the php & html work together ?
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#5
This is done in one universal snippet. PHP code is wrapped in <?php code ?>
You need to learn the basics of PHP to write snippets yourself, otherwise your site may break.