Title: Add code to function.php
Last modified: September 1, 2016

---

# Add code to function.php

 *  Resolved [rebah](https://wordpress.org/support/users/rebah/)
 * (@rebah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/)
 * Hey,
 * I’m trying to add some code the the function.php of my child theme, but I’m not
   sure how to do it the right way as everytime I try, the website crashes.
 * I believe this code previously worked when I wasn’t using a child theme. I only
   noticed the other day that the custom code was removed during an update, so that’s
   why I now want to add it to the child theme’s function.php
 * I want to hide a category so I add:
 * > action set_category_widget_parameters($args) {
   >  $args[‘exclude’] = ‘154’; return
   > $args; } add_filter(‘widget_categories_args’,’set_category_widget_parameters’);
 * This is the function.php of the child theme:
 * > <?php
   >  /* —————————————————————————- Newspaper 7 Child theme – Please do not
   > use this child theme with older versions of Newspaper Theme
   >  What can be overwritten via the child theme:
   >  – everything from /parts folder–
   > all the loops (loop.php loop-single-1.php) etc
   >  – the rest of the theme has to be modified via the theme api:
   >  [http://forum.tagdiv.com/the-theme-api/](http://forum.tagdiv.com/the-theme-api/)
   >  */
   > /* —————————————————————————-
   >  add the parent style + style.css from this folder*/
   > add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’, 1001); function theme_enqueue_styles(){
   > wp_enqueue_style(‘td-theme’, get_template_directory_uri() . ‘/style.css’, ”,‘
   > 6.1c’, ‘all’ ); wp_enqueue_style(‘td-theme-child’, get_stylesheet_directory_uri().‘/
   > style.css’, array(‘td-theme’), ‘6.1c’, ‘all’ );
   > }
 * Where do I add it or is there something wrong with the code?
 * Thanks!

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662037)
 * Hi rebah
 * Please post code & markup between backticks (`) or use the code button. Your 
   posted code may now have been permanently damaged by the forum’s parser.
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662038)
 *     ```
       function set_category_widget_parameters($args) {
       $args[‘exclude’] = ‘154’;
       return $args;
       }
       add_filter(‘widget_categories_args’,’set_category_widget_parameters’);
       ```
   
 * `action` needed to be `function`
 *  [gracer](https://wordpress.org/support/users/gracer/)
 * (@gracer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662117)
 * I crash my site everytime too
 *     ```
       function add_parameter_to_url($content) {
       	$transaction_id="";
       	if(!empty($_GET['transaction_id'])) $transaction_id=$_GET['transaction_id'];
   
       	$aff_sub="";
       	if(!empty($_GET['aff_sub'])) $aff_sub=$_GET['aff_sub'];
   
       	$aff_sub2="";
       	if(!empty($_GET['aff_sub2'])) $aff_sub2=$_GET['aff_sub2'];
   
       	$source="";
       	if(!empty($_GET['source'])) $source=$_GET['source'];
   
       	$affiliate_id="";
       	if(!empty($_GET['affiliate_id'])) $source=$_GET['affiliate_id'];
   
       	$content=str_replace('{transaction_id}',$transaction_id,$content);
       	$content=str_replace('{aff_sub}',$aff_sub,$content);
       	$content=str_replace('{aff_sub2}',$aff_sub2,$content);
       	$content=str_replace('{source}',$source,$content);
       $content=str_replace('{affiliate_id}',$affiliate_id,$content);
       	//$content="testing";
       	return $content;
       }
   
       add_filter( 'the_content', 'add_parameter_to_url',20 );
       ```
   
 * `
 *  Thread Starter [rebah](https://wordpress.org/support/users/rebah/)
 * (@rebah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662195)
 * Ah ok tnx keesie I will use code from now on.
 * Jacob, I added the code now without the site crashing, so that’s progress. But
   the code doesn’t do what I want it to do. The ‘Featured’ category (ID 154) is
   still showing in the footer widget. Any clue on a next step?
 * This is the code is my child’s function.php now.
 *     ```
       add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001);
       function theme_enqueue_styles() {
           wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', '6.1c', 'all' );
           wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), '6.1c', 'all' );
   
       function set_category_widget_parameters($args) {
       $args[‘exclude’] = ‘154’;
       return $args;
       }
       add_filter(‘widget_categories_args’,’set_category_widget_parameters’);
       }
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662199)
 * imho, your new code should be outside of the ‘theme_enqueue_scripts’ function;
   
   also, your code has some invalid single quote characters, possibly from copy/
   paste of the code. the single quotes have to be just simply `'`
 * corrected code (untested):
 *     ```
       add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001);
       function theme_enqueue_styles() {
           wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', '6.1c', 'all' );
           wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), '6.1c', 'all' );
       }
   
       function set_category_widget_parameters($args) {
       $args['exclude'] = '154';
       return $args;
       }
       add_filter('widget_categories_args','set_category_widget_parameters');
       ```
   
 *  Thread Starter [rebah](https://wordpress.org/support/users/rebah/)
 * (@rebah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662221)
 * That did the trick. Great. Thanks a lot!

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

The topic ‘Add code to function.php’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 5 participants
 * Last reply from: [rebah](https://wordpress.org/support/users/rebah/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/add-code-to-functionphp/#post-7662221)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
