Home  >  Q&A  >  body text

Create iframe with dynamic URL: efficient way to use user data

<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粉155128211P粉155128211439 days ago573

reply all(1)I'll reply

  • P粉502608799

    P粉5026087992023-08-29 11:05:51

    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?

    reply
    0
  • Cancelreply