• Resolved 50020

    (@50020-1)


    I have created a function in the theme functions.php

    function display_techincal_info() {
    // code here
    echo “Blah Blah Blah”
    }

    and I call the functions in my template pages using

    <?php display_techincal_info(); ?>

    but it doesn’t call the function. Not being 100% aux fait with how wordpress works, I added the code

    add_action( ‘init’, ‘display_techincal_info’ );

    as I had done for my custom posts, but that didn’t work either. Now I know there is nothing wrong with the code within the function becuase I am currently using it already on the same page. I just now wish to use it on more than one page – so it makes sense making it a function, and calling it from all the pages I wish to display the output….

    How do I declare the function in functions.php and how do I call it?

    thanks…

Viewing 4 replies - 1 through 4 (of 4 total)
  • use return to return a value from the function …

    please paste the real code of your function into a http://pastebin.com/ and post the link to it here;

    youy example should work;
    however, your real code might not generate any output.

    Thread Starter 50020

    (@50020-1)

    Hi,

    thanks.

    The full function is posted on pastebin here

    Thread Starter 50020

    (@50020-1)

    RESOLUTION

    I added non-conditional output to the function, and indeed the function does get called, AND the non conditional output was output.

    so it appeared that the $post->ID wasn’t available. A google search for “custon fields from functions.php’ lead me to find that $post needs to be declared as a global variable before I can use it. Might be obvious now, but it wasn’t to me at first!

    so added the code:

    global $post ;

    to the function. Hey presto!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Theme function in functions.php’ is closed to new replies.