Title: Error using function_exists in child theme
Last modified: August 12, 2021

---

# Error using function_exists in child theme

 *  Resolved [anoktear](https://wordpress.org/support/users/anoktear/)
 * (@anoktear)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/)
 * Hello,
    I’m trying to override the generate_get_media_query of theme-functions.
   php in the child theme functions.php:
 *     ```
       if ( ! function_exists( 'generate_get_media_query' ) ) {
   
           function generate_get_media_query( $name ) {
               $desktop = apply_filters( 'generate_desktop_media_query', '(min-width:1025px)' );
               $tablet = apply_filters( 'generate_tablet_media_query', '(min-width: 769px) and (max-width: 1024px)' );
               $mobile = apply_filters( 'generate_mobile_media_query', '(max-width:768px)' );
               $mobile_menu = apply_filters( 'generate_mobile_menu_media_query', $mobile );
   
               $queries = apply_filters(
                   'generate_media_queries',
                   array(
                       'desktop' => $desktop,
                       'tablet' => $tablet,
                       'mobile' => $mobile,
                       'mobile-menu' => $mobile_menu,
                   )
               );
   
               return $queries[ $name ];
           }
   
       }
       ```
   
 * However, I keep getting the **Fatal error: Cannot redeclare generate_get_media_query()**.
 * What am I doing wrong?
    -  This topic was modified 4 years, 9 months ago by [anoktear](https://wordpress.org/support/users/anoktear/).

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

 *  [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14763398)
 * Hi there,
 * You can’t have the same name for a function you’re making.
 * `generate_get_media_query` function name already exists so you can’t redeclare
   it.
 * Can you tell us what you’re trying to do?
 *  Thread Starter [anoktear](https://wordpress.org/support/users/anoktear/)
 * (@anoktear)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14764069)
 * Hi [@ejcabquina](https://wordpress.org/support/users/ejcabquina/),
 * I would like to change this line on that function:
 * `$mobile_menu = apply_filters( 'generate_mobile_menu_media_query', $mobile );`
 * to another media query value:
 * `$mobile_menu = apply_filters( 'generate_mobile_menu_media_query', '(max-width:
   1920px)' );`
 * I didn’t want to change in /inc/theme-functions, I understand that is best to
   place in the child theme functions.php.
 * I tried using the **if function_exists**, but I must be doing it wrong.
 * Thanks
 *  Theme Author [Tom](https://wordpress.org/support/users/edge22/)
 * (@edge22)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14766783)
 * Hi there,
 * This is where filters are helpful.
 * For example:
 *     ```
       add_filter( 'generate_mobile_menu_media_query', function() {
           return '(max-width:1920px)';
       } );
       ```
   
 * Let us know if you need more info 🙂
 *  Thread Starter [anoktear](https://wordpress.org/support/users/anoktear/)
 * (@anoktear)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14768865)
 * That’s it [@edge22](https://wordpress.org/support/users/edge22/) , thank you 
   so much.
    What a great support experience for a WordPress theme.
    -  This reply was modified 4 years, 9 months ago by [anoktear](https://wordpress.org/support/users/anoktear/).
 *  Theme Author [Tom](https://wordpress.org/support/users/edge22/)
 * (@edge22)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14770193)
 * You’re welcome! Glad we could help 🙂

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

The topic ‘Error using function_exists in child theme’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/generatepress/3.6.1/screenshot.
   png)
 * GeneratePress
 * [Support Threads](https://wordpress.org/support/theme/generatepress/)
 * [Active Topics](https://wordpress.org/support/theme/generatepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/generatepress/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/generatepress/reviews/)

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [function_exists](https://wordpress.org/support/topic-tag/function_exists/)

 * 5 replies
 * 3 participants
 * Last reply from: [Tom](https://wordpress.org/support/users/edge22/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/error-using-function_exists-in-child-theme/#post-14770193)
 * Status: resolved