brainiac
Member
Posted 2 years ago #
Hi,
I just wrote my first theme function, which is supposed to
insert text into sidebar. It works fine from command line,
but WP displays its text, instead of regular page.
e.g. function foo() { echo 'foo'; }
then <li><?php foo(); ?>
But all I see is 'foo' - not the rest of the page.
I have done this dozens of times with CGI and Javascript,
what do I have to differently to get it to work with PHP/WP ?
Thanks!
More info about the problem please...
If in your functions file you have.
function foo() { echo 'foo'; }
Then in a template file you have..
<?php foo(); ?>
The result is...
foo
That's what i'd expect anyway, is that not what happens?
brainiac
Member
Posted 2 years ago #
Thanks for replying.
WP *only* displays foo e.g: if page is:
<h1>title</h1><p>text</p><p><?php foo()?></p>
all I see is foo
Tried adding header('Content-type: text/plain')
like I would do from js/ajax then all I got was
plain text 'foo` -
page displays normally I remove function call.
Was that clear?
foo() only contains foo, so that will be returned/printed on screen...
Did you expect something different?
Seems to me it's behaving just as it should, so i'm a little confused..
brainiac
Member
Posted 2 years ago #
Regular site worked fine.
After I added style function, I only saw the output
of my function -- instead of page, not added to page. Does it make sense now?
I rewrote it using JS to call PHP, just adding text/plain header,
and it works fine,
however I would like to know what I did wrong, because I would rather
use one php statement instead of a couple of JS functions.
Well lets see how your functions file looks and the file you're including it into.
Do you get any PHP errors output to the screen?...
Please post code from functions file and template file where you're using the function..
Thanks,
brainiac
Member
Posted 2 years ago #
It works: WP Test
Thanks!