• Ok, first off, if this has been answered, or is the wrong forum, i sincerely apologize, and for what its worth, ive spent hours scouring google, etc. trying to patch this together myself. I have very little, to no experience with php, and im assuming thats where the answer to this lies, so again, i apoligize, and pretend youre explaining it to your 5 year old lol. ok… I want to call a url in an iframe on a page (in WP obv) and want to call the username as a variable in that url. So something like
    //
    <iframe src=”https://example.com/whatever.php?part=$variable_here”&gt; </iframe>

    so from what ive gathered, i can call wp_get_current_user into a variable named $variable_here and that should work. However, where im lost is, the very little background I have is in straight oldschool html, and WP, and this is completely layman’s, is all php/css based? So is it possible to call that within a page? Can I edit/create a php file in dreamweaver to do this, and then call that within a page? Can it just be done from within wordpress? Am i completely lost? lol.. any help, even just a nudge in the right direction would be beyond appreciated. Thanks so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • If you want to do this inside a pges content, you should think about creating your own Shortcode that will output the iframe code.

    There’s a lot of good examples and code in the page that I’ve linked, so that will get it working, and then you would just output the iframe code in your shortcode function, something like this (not tested…)

    $html = '<iframe src="https://example.com/whatever.php?part='  .wp_get_current_user() . '"> </iframe>';
    
    return $html;
    Thread Starter wp_chats2

    (@wp_chats2)

    ok, so this was my best attempt. I tried making this a shortcode plugin, so this is the code for said plugin, but when i tried to activate, it said could not activate, plugin triggered a fatal error. Thanks again for the help…

    <? php
    
    /**
    *Plugin Name: statpage_iframe
    *Plugin URI: example
    *Description: Stat page plugin
    *Author: example
    *Author URI: example
    *Version: 1.0
    */
    
    add_shortcode('statpage_iframe', 'getuser_iframe');
    
    function getuser_iframe($atts, $content = null) {
    
    	$rid = wp_get_current_user();
    	return $rid->user_login;
    	$html = '<iframe src="https://example.com/ccXML.php?part=' . $rid . '"> </iframe>';
    	return $html;
    }

    Thanks again, this is a massive help!

    It all looks good apart from two small things

    First, you’ve got a space between <? php when it should be just <?php without the space.

    Second, you don’t need to return the value for $rid->user_login, you’d use that in the HTML. So, your completed code should be like this:

    <?php
    /**
    *Plugin Name: statpage_iframe
    *Plugin URI: example
    *Description: Stat page plugin
    *Author: example
    *Author URI: example
    *Version: 1.0
    */
    
    add_shortcode('statpage_iframe', 'getuser_iframe');
    
    function getuser_iframe($atts, $content = null) {
    	$rid = wp_get_current_user();
    	$html = '<iframe src="https://example.com/ccXML.php?part=' . $rid->user_login . '"> </iframe>';
    	return $html;
    }
    Thread Starter wp_chats2

    (@wp_chats2)

    I can’t thank you enough, its working perfect! It also opened up the door to what can be done with php, and scripting in general, which is ridiculously cool, so thank you again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding username as variable in a url redirect’ is closed to new replies.