Create iframe with dynamic URL: efficient way to use user data
P粉155128211
P粉155128211 2023-08-28 23:47:44
0
1
588
<p>First time posting a question here. I'm definitely not a coding expert, I've learned some HTML and CSS through Google, StackOverflow, and a lot of trial and error, but this question seems to be a PHP question, and I know next to nothing about PHP. </p> <p>I'm creating a subscription WordPress website and I need to create an iframe with a dynamic src value. </p> <p>The first part of the src value is the same for every user (e.g. https://app.example.com/autoin/), then it should be completed with a unique code assigned to each user. The code is in a field in the user's profile. I'm currently using the second address line. The id or name of this field is address-two. </p> <p>The closest code I found that worked was the code below, which I added directly to the page I would use, using WPBakery's raw HTML box. </p> <pre class="brush:php;toolbar:false;"><?php $current_user = wp_get_current_user(); if($current_user) { ?> <iframe class="metricool-iframe" src="https://app.example.com/autoin/<?php echo $current_user->address-two; ?>> </iframe> <?php } ?></pre> <p>When I check the page source in Chrome, I can see that the URL is still <code>https://app.example.com/autoin/<?php echo $current_user->address- two; ?></code> So, it doesn't actually work. </p> <p>Excuse me, is there anything I can do to improve the above code? Or is there any other way? Please keep in mind that I'm completely new to this :P</p> <p>Thanks in advance! </p> <p>Yeah. </p>
P粉155128211
P粉155128211

reply all(1)
P粉502608799

You can try this:

<?php
$current_user = wp_get_current_user();
if(isset($current_user)) {
  $useraddress = $current_user->address-two;
  echo "<iframe class='metricool-iframe' src='https://app.example.com/autoin/".$useraddress."'></iframe>";
} else { 
  echo "No User Set!";
?>

If this helped you, please mark it as answer, it means a lot to me!

edit:

What is your file name? (For example: index.html, index.php)

Which web server are you using, and are you 100% sure that it has php running on it?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template