mix html and shortcode in a page or post

I use a child theme and in this child theme I have added functions so I can use shortcodes to display user information, such as name with [user-name] or email with [user-email].

When I put my shortcodes in my posts or pages, they work just fine.

But I need to do something more.

I need to display in a WP page statistics information about the connected user. This information comes from an application outside of WP.

So I need to display an iframe in a WP page, with a URL with a parameter given by my short code.

If I put this:
<iframe width="600" height="200" src="http://www.mydomain.com?user=[user-id]"</iframe>
I get this as iframe URL:
http://www.mydomain.com?user=user-id

And if I put this:
<iframe width="600" height="200" src="http://www.mydomain.com?user=[user-id]"</iframe>
I get this as iframe URL:
http://www.mydomain.com?user=theGoodUserId

What should I put to get the correct iframe URL:
http://www.mydomain.com?user=theGoodUserId

  • Éric Malalel
    • The Incredible Code Injector

    I am sorry but I have the feeling your answer is out of context, or maybe I don't understand it at all.

    Let me restate my question, as formatting problems in my previous post may have lead you to the wrong way.

    I use a child theme, and in this child theme I have added functions so I can use shortcodes to display user information, such as name with [user-name] or email with [user-email].

    When I put my shortcodes in a WP post or page, they work just fine.

    But I need to do something more.

    I want to display in a WP page statistics information about the connected user which comes from an application outside of WP.

    So I need to display an iframe in a page, with a URL with a parameter given by my short code.

    If I put this in WP editor:
    <iframe width="600" height="200" src="http://www.mydomain.com?user=[user-id]"</iframe>
    I get this as iframe URL:
    http://www.mydomain.com?user=user-id

    And if I put this in WP editor:
    <iframe width="600" height="200" src="http://www.mydomain.com?user=<code>[user-id]</code>"</iframe>
    I get this as iframe URL:
    http://www.mydomain.com?user=<code>theGoodUserId</code&gt;

    What should I put in the WP editor to get the correct iframe URL:
    http://www.mydomain.com?user=theGoodUserId

  • Jude
    • DEV MAN

    Hi again @Luce Tancil

    Thanks for clarifying.

    Yeah the formatting helped. I misunderstood that you were entering these in the editor, thinking these iframes were being created in your page template.

    Anyhoo Id still say go with HEREDOC, create a shorcode say [user-iframe] and use that in the page.

    So the final code will look something like

    function user-iframe_func( $atts ) {
        $id = do_shortcode('[user-id]');
        $iframe = <<<IFRAME
    <iframe width="600" height="200" src="http://www.mydomain.com?user=$id"</iframe>
    IFRAME;
        return $iframe;
    }
    add_shortcode( 'user-iframe', 'user-iframe_func' );

    Hope that helps

    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.