WordPress.org

Support

Support » Themes and Templates » [Resolved] How to add a function to functions.php?

[Resolved] How to add a function to functions.php?

  • Hello dear wordpressoholics,
    I am stuck with a problem. I want to add the following code to my functions.php:

    add_action('wp_enqueue_scripts', 'mh_superfish');
    function mh_superfish() {
    	if(!is_admin()) wp_enqueue_script('superfish', template_url( 'js/superfish.js', __FILE__ ), array('jquery'), '1.4.8', TRUE);
    	if(!is_admin()) wp_enqueue_script('superfish-args', template_url( 'js/superfish_args.js', __FILE__ ), array('jquery'), '1.4.8', TRUE);
    }

    But every time I try something, I always got a fatal error message. Please help! Thank you!

    BR
    Codex22

Viewing 15 replies - 1 through 15 (of 24 total)
  • esmi

    @esmi

    Forum Moderator

    What theme are you using?

    I use my own theme. (http://ammantempel.net) and now I want to add this code to my functions.php

    esmi

    @esmi

    Forum Moderator

    Do you have any knowledge of PHP?

    Just a little. I am not that good at php.

    esmi

    @esmi

    Forum Moderator

    What is the exact error message?

    This is the message I got.

    >Fatal error: Cannot redeclare mh_superfish() (previously declared in C:\xampp\htdocs\wordpress\wp-content\plugins\superfish\superfish.php:13) in C:\xampp\htdocs\wordpress\wp-content\themes\artist_theme\functions.php on line 18

    esmi

    @esmi

    Forum Moderator

    Your new functions.php code is conflicting with your superfish plugin. You cannot use both at the same time.

    Okai I deactivated the plugin, but now I get this message:

    Fatal error: Call to undefined function template_url() in C:\xampp\htdocs\wordpress\wp-content\themes\NTT-Cindy-Theme\functions.php on line 16

    esmi

    @esmi

    Forum Moderator

    You’re using a completely different theme now! Where did you download this theme from?

    That was a theme from a tutorial (newthinktank.com). But even I swtich back to my theme, I get this message:

    Fatal error: Call to undefined function template_url() in C:\xampp\htdocs\wordpress\wp-content\themes\artist_theme\functions.php on line 16

    esmi

    @esmi

    Forum Moderator

    Try removing the template_url() function.

    I tried, but it is a bit hard. How do i rewrite this code:

    plugins_url( 'js/superfish.js', __FILE__ ), array('jquery'), '1.4.8', TRUE)

    so it will look in the theme folder???

    [No bumping. If it’s that urgent, consider hiring someone.]

    esmi

    @esmi

    Forum Moderator

    I thought you created this theme?

    Yes I did, but this code is form a plug-in called “superfish menu”. I wanted to integrate this plug-in into my theme. So I thought I could do this by add this code to the functions.php. I don’t want the plug-in to be activated, I want it to be active straight from the beginning.

    esmi

    @esmi

    Forum Moderator

    Check the plugin’s documentation.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘[Resolved] How to add a function to functions.php?’ is closed to new replies.
Skip to toolbar