[resolved] how to display text from functions.php (7 posts)

  1. Mitchell Miller
    Posted 6 years ago #

    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 ?


  2. Mark / t31os
    Posted 6 years ago #

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


    That's what i'd expect anyway, is that not what happens?

  3. Mitchell Miller
    Posted 6 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?

  4. Mark / t31os
    Posted 6 years ago #

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

  5. Mitchell Miller
    Posted 6 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.

  6. Mark / t31os
    Posted 6 years ago #

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


  7. Mitchell Miller
    Posted 5 years ago #

    It works: WP Test


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.