WordPress.org

Ready to get started?Download WordPress

Forums

Show plugin in a page (5 posts)

  1. -javier-
    Member
    Posted 5 years ago #

    I have a weird problem with a custom plugin.

    This is the code to show inside a page:

    // replace tag in content with myplugin
    function myplugin_init($content){
    	if( strpos($content, '<!--myplugin-->') !== false ){
    		$code = myplugin_function();
    		$content = str_replace( '<!--myplugin-->', $code, $content );
    	}
    	return $content;
    }

    and then:

    add_filter('the_content','myplugin_init');

    Looks ok, but the plugin always show first in the page, no matter where I put it.

    In my page have some text, and then: <!--myplugin-->. But the plugin goes first. The weird thing is the html code show the plugin code first, so it's not only a css float, position problem.

    I thinks the problem is the way the plugin replace the content. ┬┐Any ideas?

    PS: Sorry about my english, not my native language.

  2. Samuel B
    moderator
    Posted 5 years ago #

    Can't you just "echo" it exactly where you want it to come up?

  3. -javier-
    Member
    Posted 5 years ago #

    Hi,
    No, because It's a regular page. The content is filled by the Write tab, in the administration panel of WordPress.

  4. -javier-
    Member
    Posted 5 years ago #

    Ok, Update: If I change the $code to this:

    // replace tag in content with myplugin
    function myplugin_init($content){
    	if( strpos($content, '<!--myplugin-->') !== false ){
    		$code = "Hello world!";
    		$content = str_replace( '<!--myplugin-->', $code, $content );
    	}
    	return $content;
    }

    It's show correctly. When it's a function, goes first. In the content of the page (by the write tab in de administratios panel of wordpress) I have:

    some text..... bla bla...

    <!--myplugin-->

    more text.... bla bla...

    And the result is a page like that:

    PLUGIN CONTENT

    some text..... bla bla...
    more text.... bla bla...

  5. -javier-
    Member
    Posted 5 years ago #

    Ok. I figured out.

    The second function called by the myplugin_init function (In this case "myplugin_function" or, in others words, the plugin itself), can't contain an "echo", it must be changed by this:

    $somevar = "Hello world!";
    return $somevar;

    ...and that's all. All works fine now.

Topic Closed

This topic has been closed to new replies.

About this Topic