• When I started customizing my wordpress, I always used the google search as my first weapon. Every time I found some order to add some codes in my function.php file. I tried several time. But I couldn’t do it. Can any one please please & please tell me how to add a code successfully in my function.php. I’ll be grateful..

Viewing 5 replies - 1 through 5 (of 5 total)
  • I assume you want to edit the functions.php file for your theme?

    There are two ways to do this:

    Go to your WordPress dashboard (www.yoursite.com/wp-admin).
    Navigate to Appearance >> Editor. Choose the theme you want to edit from the dropdown and the file from the right sidebar. (This method will only work if your WordPress files are writeable (http://codex.wordpress.org/Changing_File_Permissions).

    OR

    Use your favourite FTP manager to access the location of your WordPress files. Navigate to wp-content/themes/your-theme.
    Open up the functions.php file and edit to your heart’s content!

    The above methods will only work if your theme includes a functions.php file. If no file exists in the wp-content/themes/your-theme directory, then create it.

    Thread Starter sumonism

    (@sumonism)

    Thanks. Where to find I know, but where to add code in the file? Just give me the example.

    anywhere….

    Your functions.php must start with an opening php tag, looks like:

    <?php

    That’s really the only rule. I just add code underneath any existing code. Things don’t have to be in a particular order.

    You must also not ‘nest’ php tags…. so if you copy/paste code don’t accisdentally put in anotehr opening php tag… like:

    <?php
    
    existing code
    
    <?php
    
    new code you pasted
    
    ?>

    That’s about all the generic help I can give… what specific trouble are you having?

    Thread Starter sumonism

    (@sumonism)

    I understand a little bit. Now I am specifically telling you about my problem Mr. Voodoo-

    I want to put the following code in my function.php

    //hook the administrative header output
    add_action('admin_head', 'my_custom_logo');
    
    function my_custom_logo() {
    echo '
    <style type="text/css">
    #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }
    </style>
    ';
    }

    Please show me like you show in your recent post Mr. Voodoo. Thanks..

    [Please post code snippets between backticks or use the code button.]

    You should be able to just paste that code in your themes functions.php file.

    Does it already have an existing functions.php file in it?

    You can paste it right at the bottom.

    If you have a closing php tag, it goes above that

    <?php
    
    existing code
    
    your new code
    
    ?>

    If it does not have a closing php tag, that is fine as well. They are not needed there, I never have one

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add codes in function.php?’ is closed to new replies.