• Resolved Riley Magnuson

    (@rmagnuson)


    I have run into a bug with my plugin that is set to display a set of HTML and PHP where the shortcode is placed.

    Basically, I want all the code I have placed inside of my function to display where I put the shortcode, however with my current setup, it’s displaying at the very top of the content section on a page, and I can’t find a way to adjust it.

    This is the code I’m using now:

    function mod_myaccount_frame() { ?>
        <div>
        <iframe id="mainFrame" name="mainFrame" src="https://www.myorderdesk.com/settings.asp?Provider_ID=<?php echo $opt_val; ?>" scrolling="no" allowtransparency="true" style="border:0px solid gray; background-color:transparent; width:100%; height:1600px" onload="window.parent.parent.scrollTo(0,0)"></iframe>
        </div>
        <?php //Enqueue the iframe stylization
        wp_enqueue_script( 'mod_frameresizer', plugins_url( 'Resources/iframeresizer.min.js' , __FILE__), $in_footer = true ); //Calls the resize code
        wp_enqueue_script( 'mod_frameresizer1', plugins_url( 'Resources/MODSkinService.js' , __FILE__), $in_footer = true ); //Calls the mod skin code
        wp_enqueue_script( 'mod_frameresizer2', plugins_url( 'Resources/ifrzsk.js' , __FILE__), $in_footer = true ); //Runs the resize and skin code ?>
    <?php }
    
    add_shortcode( 'mod-myaccount', 'mod_myaccount_frame' );

    How can I get the div and iframe code to be inserted exactly where the shortcode was put?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • All shortcodes must return their generated output. None of the output should be output by the shortcode function.
    Your function is outputting directly. Put it in a string variable and return it. (not the enqueues, just the actual output)

    Hello Riley try this, for output content, in shortcode function

    function my_shortcode() {
    	ob_start();
    	?> <HTML> <here> ... <?php
    	return ob_get_clean();
    }

    and separe this

    wp_enqueue_script( 'mod_frameresizer', plugins_url( 'Resources/iframeresizer.min.js' , __FILE__), $in_footer = true ); //Calls the resize code
        wp_enqueue_script( 'mod_frameresizer1', plugins_url( 'Resources/MODSkinService.js' , __FILE__), $in_footer = true ); //Calls the mod skin code
        wp_enqueue_script( 'mod_frameresizer2', plugins_url( 'Resources/ifrzsk.js' , __FILE__), $in_footer = true ); //Runs the resize and skin code ?>
    Thread Starter Riley Magnuson

    (@rmagnuson)

    Thanks for the input all, I managed to end up using this based on your input:

    function mod_myaccount_frame() {
    	
    	//Enqueue the iframe stylization
        wp_enqueue_script( 'mod_frameresizer', plugins_url( 'Resources/iframeresizer.min.js' , __FILE__), $in_footer = true ); //Calls the resize code
        wp_enqueue_script( 'mod_frameresizer1', plugins_url( 'Resources/MODSkinService.js' , __FILE__), $in_footer = true ); //Calls the mod skin code
        wp_enqueue_script( 'mod_frameresizer2', plugins_url( 'Resources/ifrzsk.js' , __FILE__), $in_footer = true ); //Runs the resize and skin code
    	
    	$opt_name = 'mod_number';
    	$opt_val = get_option( $opt_name );
    	
    	$testvar1 = '<div><iframe id="mainFrame" name="mainFrame" src="https://www.myorderdesk.com/settings.asp?Provider_ID=' . $opt_val . '" scrolling="no" allowtransparency="true" style="border:0px solid gray; background-color:transparent; width:100%; height:1600px" onload="window.parent.parent.scrollTo(0,0)"></iframe></div>';
    	
    	return $testvar1;
    }
    //shortcode
    add_shortcode( 'mod-myaccount', 'mod_myaccount_frame' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display iFrame exactly where shortcode is placed’ is closed to new replies.