Title: Moving from child theme to Code snippets: Code error
Last modified: April 3, 2022

---

# Moving from child theme to Code snippets: Code error

 *  Resolved [nickk40](https://wordpress.org/support/users/nickk40/)
 * (@nickk40)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/moving-from-child-theme-to-code-snippets-code-error/)
 * I’ve followed [this tutorial](https://torquemag.io/2016/09/add-custom-styles-wordpress-editor-manually-via-plugin/)
   to add custom styling to the wordpress editor. For example, I created a child
   theme and to `functions.php` I added code such as:
 *     ```
       function add_style_select_buttons( $buttons ) {
       	array_unshift( $buttons, 'styleselect' );
       	return $buttons;
       }
       add_filter( 'mce_buttons_2', 'add_style_select_buttons' );
       ```
   
 * It all worked. But now I no longer want to use a child theme but instead add 
   the code by using the Code Snippets plugin. However, when I add the above code(
   and the same problem is there for other code) as a Snippet and want to activate
   it, I get the error:
 * > The snippet has been deactivated due to an error on line 2:
   >  Cannot redeclare
   > function add_style_select_buttons.
 * What adjustment do I need to make to the code from the tutorial as to make this
   work with Code Snippets instead of a Child theme?

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

 *  Thread Starter [nickk40](https://wordpress.org/support/users/nickk40/)
 * (@nickk40)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/moving-from-child-theme-to-code-snippets-code-error/#post-15522582)
 * Ah, I get it: when I tried to activate the snippet, I also still had the child
   theme. So I had the same function name in two locations.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/moving-from-child-theme-to-code-snippets-code-error/#post-15522602)
 * That’s exactly it! If you want to avoid this sort of error completely in the 
   future, I recommend writing your functions as anonymous callbacks instead, like
   this:
 *     ```
       add_filter( 'mce_buttons_2', function ( $buttons ) {
       	array_unshift( $buttons, 'styleselect' );
       	return $buttons;
       } );
       ```
   

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

The topic ‘Moving from child theme to Code snippets: Code error’ is closed to new
replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/moving-from-child-theme-to-code-snippets-code-error/#post-15522602)
 * Status: resolved