Bestway to write php functions

I have seen that every theme use this format

if( !function_exists( 'blogrock__f' )) :
   function blogrock__f () {
   /// code here
  }
endif;
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?

Thanks

Topic function-exists theme-development Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.