1

What it the advantages of having the code in wp-blog-header.php seperate from index.php in wordpress?

I tried to move the code in wp-blog-header.php to index.php and the website loads perfectly fine, I think.

Could someone please explain about the advantage of running a require function in index to call wp-blog-header instead to writing the wp-blog-header code in index

1 Answers1

0

Code reuse. There is not only index.php as entry-script. Every entry-script that wan't to load Wordpress core library functionalities and templating functionalities can require that file.

Using require/include(_once) is the historic way in PHP to do code-reuse.

  • include has/is often used for (HTML) tamplating code.
  • require is more often used for PHP program code, like function and class definitions.

These are not rules set in stone, it's more what common usage patterns are. Both are very close to each other:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • I am new to PHP and Wordpress. I tried to read about Code reuse online but the idea seem to be scattered. Would you be able to comprehend it for me –  Apr 03 '15 at 06:32
  • Let's say you've got two pages with the same header. You could write the same header two times or you could write the header once and re-use the code two times. – hakre Apr 03 '15 at 06:43