Forums

HTML code in shortcode puts content at the top (4 posts)

  1. OM2
    Member
    Posted 7 months ago #

    I'm writing a simple shortcode that inserts HTML wherever I put a shortcode, i.e. [myHTML]

    I'm using the shortcode in the middle of my text

    But, for some reason it ALWAYS appears at the top of the page content

    How do I stop this?

    How do I make the content appear exactly where I put the shortcode?

    It's really annoying!

    Thanks

    Omar

  2. nofearinc
    Member
    Posted 7 months ago #

    There is probably some caching issue, try using ob_* functions to wrap your shortcode (sample: https://tobymackenzie.wordpress.com/2010/02/28/wordpress-shortcodes/ )

  3. OM2
    Member
    Posted 7 months ago #

    thanks for the reply
    not working for me
    i read and followed instructions - no luck

    this is my code:

    <?php
    /*
    Plugin Name: My Plugin
    Version:     1.0
    Description: My Plugin
    */
    
    add_shortcode( 'myplug', 'myplug' );
    function myplug () {
    ob_start();
    ?>
    <div>Hello World</div>
    <?php }
    $fncReturn = ob_get_contents();
    ob_end_clean();
    return $fncReturn;
    ?>

    I've over simplified to illustrate my point

    The shortcode is put in the middle of text

    But 'Hello World' still appears at the top

    Where am I going wrong?

    Thanks

    Omar

  4. OM2
    Member
    Posted 4 months ago #

    i posted this question a long time ago
    i'm still having the same problem!

    is there anyway of controlling when the shortcode code executes?

    for me the whole idea of using shortcodes is defeated :(

    or am i missing something?

Reply

You must log in to post.

About this Topic