• 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can’t you just “echo” it exactly where you want it to come up?

    Thread Starter -javier-

    (@javier-2)

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

    Thread Starter -javier-

    (@javier-2)

    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…

    Thread Starter -javier-

    (@javier-2)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show plugin in a page’ is closed to new replies.