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

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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?

    Thread Starter Mitchell D. Miller

    (@brainiac)

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

    Thread Starter Mitchell D. Miller

    (@brainiac)

    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,

    Thread Starter Mitchell D. Miller

    (@brainiac)

    It works: WP Test

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to display text from functions.php’ is closed to new replies.