How to customize or move core files?

The last couple of days I run into the fact that I had to make some customization’s concerning core files. Like WordPress core files and Bootstrap core files.
Is there a best practice to handle this or is there a golden rule never to touch core files?

Related posts

Leave a Reply

2 comments

  1. Yes, there is a golden rule to never touch core files, because those changes would get overwritten with the next update. You should create a WordPress plugin to hook in and tweak WordPress functionality. You should use SCSS or LESS to customize Bootstrap, or use simple CSS to overwrite their styles. If you need to overwrite jQuery core or other JavaScript methods, you can do so without changing core files:

    // Reference to the real method
    var realHtml = $.fn.html;
    
    // Your overwriting method
    $.fn.html = function () {
    
        // Do something here, like
        console.log(this, arguments);
    
        // Then call original method
        return realHtml.apply(this, arguments);
    }
    
    // Use it
    $('h1').html();
    
  2. I think the best approach is to create custom file and keep all your changes there, this approach will overwrite core code and allow to revert back to default styles if necessary.
    If you make changes directly to the default code, it becomes very difficult to maintain and keep track of changes.
    In other words, we have the following: When defining a code snippets twice, the last definition of a snipped is used!