Title: How to add code in PHP file&#8230; function.php
Last modified: August 22, 2016

---

# How to add code in PHP file… function.php

 *  Resolved [mnhfile](https://wordpress.org/support/users/mnhfile/)
 * (@mnhfile)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/)
 * I want to add this(below) custom code to my function.php file and i don’t know
   how to add this whether i add this code as it is or add php tag after or before
   it…like (<?php(—code—-)?>)
 *     ```
       // stop wp removing div tags
       function ikreativ_tinymce_fix( $init )
       {
           // html elements being stripped
           $init['extended_valid_elements'] = 'div[*],article[*]';
   
           // don't remove line breaks
           $init['remove_linebreaks'] = false; 
   
           // convert newline characters to BR
           $init['convert_newlines_to_brs'] = true; 
   
           // don't remove redundant BR
           $init['remove_redundant_brs'] = false;
   
           // pass back to wordpress
           return $init;
       }
       add_filter('tiny_mce_before_init', 'ikreativ_tinymce_fix');
       ```
   

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

 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489188)
 * navigate to
 *     ```
       /wp-content/themes/your-theme-directory/functions.php
       ```
   
 * and add the code at the end of the file there. you do not need the PHP tags at
   all. The functions file already has an opening php tag `<?php` in it.
 *  Thread Starter [mnhfile](https://wordpress.org/support/users/mnhfile/)
 * (@mnhfile)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489189)
 * what happen if I add <?php before and ?> at the end of the code… Is the code 
   get wronged by doing this…
 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489192)
 * if there is already an opening php tag at the begining of the file, you do not
   need to add a new tag.
 * It is not recommended to use the closing php tag in the function file. Why do
   you try and see what happened..
 * paste
 *     ```
       // stop wp removing div tags
       function ikreativ_tinymce_fix( $init )
       {
           // html elements being stripped
           $init['extended_valid_elements'] = 'div[*],article[*]';
   
           // don't remove line breaks
           $init['remove_linebreaks'] = false; 
   
           // convert newline characters to BR
           $init['convert_newlines_to_brs'] = true; 
   
           // don't remove redundant BR
           $init['remove_redundant_brs'] = false;
   
           // pass back to wordpress
           return $init;
       }
       add_filter('tiny_mce_before_init', 'ikreativ_tinymce_fix');
       ```
   
 * at the end of the functions.php file of your theme (not WordPress core functions.
   php).
 *  Thread Starter [mnhfile](https://wordpress.org/support/users/mnhfile/)
 * (@mnhfile)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489200)
 * Thank you justin greer
 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489202)
 * Your welcome.

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

The topic ‘How to add code in PHP file… function.php’ is closed to new replies.

## Tags

 * [php code](https://wordpress.org/support/topic-tag/php-code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/how-to-add-code-in-php-file-functionphp/#post-5489202)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
