ThemeShaper Forums » Thematic


Adding New Child Theme Function

(7 posts)
  • Started 11 years ago by echolte
  • Latest reply from helgatheviking
  • This topic is resolved
  1. I'm not trying to override an existing function.
    I want to add a brand new function to a child theme , but get this error.
    Fatal error: Call to undefined function newfunction() in ...
    I'm a little embarrassed I couldn't do something this simple.

    Here's the code:
    function eh-newfunction() {
    echo('IT WORKS! ***************************************************************');

    Posted 11 years ago #
  2. I changed my code to this , but still not working.

    function custom_newfunction() {
    echo('IT WORKS! *********************************************************************');

    Posted 11 years ago #
  3. Close. Try this:

    function newfunction() {
    	echo 'IT WORKS! ***************************************************************';

    You can read about the proper syntax for echo here:

    You can also add a number to specify where the new function gets placed in the header:

    function newfunction() {
    	echo 'IT WORKS! ***************************************************************';
    add_action('thematic_header','newfunction', 4);

    If you're ever having trouble with a an action or filter, try doing a search in the forums for the function first (e.g. thematic_header). Generally there will be a few examples you can work off of.

    Posted 11 years ago #
  4. This did not work for me Devin. I don't know why.
    It looks good & I've seen this method in other posts.
    I'm a little confused.

    Posted 11 years ago #
  5. Robo

    So if I understand correctly Devin, you can add any valid new function, and determine where it goes using a number.

    But how are the numbers arranged?

    And what if there is an existing fn with that number? Is it replaced?

    Is this numbering a thematic thing, or is this built into Wordpress?

    Sorry about all the questions :-) But I'm sure others will be wondering also.

    Posted 11 years ago #
  6. Robo

    Also, why add_action rather than add_function? Is this a naming problem?

    Posted 11 years ago #
  7. i dont know why it is add_action. it just is. you can't add a function to any 'number', but you can add it to any "hook". i still dont know what to semantically call those numbers, but they represent sort of mini-hooks (in an order) in the thematic_header function. i believe they also exist in a few other places but the header is the main culprit. most functions do not have them. for example:

    function add_stuff() {
    echo 'it works';

    here is a diagram of hooks. there are some new ones, but this is mostly complete and i find it vveeeerrry helpful.

    you can add an action to any hook, but if there is already an action there that you want to override then you should delete the one that is there first.

    the other place i spend a lot of time is in the thematic library folder... especially extensions. that is the heart of thematic imo.

    a great tut:

    and some useful snippets:

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.