I have seen that every theme use this format

if( !function_exists( 'blogrock__f' )) :
   function blogrock__f () {
   /// code here
add_action('after_setup_theme', 'blogrock_setup');

I am pretty bored writing if.. endif blocks. I know I can create new classes to avoid this . But can I do this in this way?

if (!function_exists('theme_add_next_page_button')) { 
function theme_add_next_page_button(){
   // function blocks
add_filter( 'mce_buttons', 'theme_add_next_page_button', 1, 2 );    

Can I remove function conflict by this way? If there are otherways,what are those? And does my later way impact negative on theme performance?


  • 2
    Your second way is almost the same as the first way, just using a different style of if blocks... – Tim Malone Apr 26 '16 at 6:04

The use of function_exists is a very bad habit that should simply be avoided in favor of using actions and filters.

If you want child themes to be able to override some functionality you need to be very specific about which one and how, and function_exists is usually not specific enough for that.

| improve this answer | |
  • Thank you. Anyway if there is duplicate function how can I check it? I mean prevent showing php error for same function? – Busted Angon Apr 26 '16 at 5:36
  • @BustedAngon why would you want to prevent that? – Mark Kaplun Apr 26 '16 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.