How to Include and Exclude Code in Header.php


A header.php file contains the PHP website code that loads before the body and footer code. You place important header information, such as login buttons and logo information, in the PHP header file. If you want to exclude any of the PHP header code, you must comment out the code. PHP has a specific syntax to comment out code, which stops the compiler from running the statements when the user calls the website pages.

  • Right-click the header.php file in your project directory on your computer. Select "Open With," then double-click the PHP editor you use to edit the code.

  • Scroll down to the line of code you want to comment out. If you want to comment out only one line of code, type "//" or "#" -- without the quotes -- in front of the code statement. The PHP compiler ignores only the current line of PHP code.

  • Type "/" in front of the first of multiple lines of code. At the end of the last line you want to comment out, type "/". For instance, the following code comments out the first "echo" statements but executes the last "echo" statement:

    /* echo "first line"

    echo "last line" */

    echo "this line executes";

  • Press the "Ctrl" and "S" keys on your keyboard to save the changes to your code. Click the "Run" button in the editor to view the PHP changes in a browser.

Related Searches


Promoted By Zergnet


You May Also Like

  • How to Change a Font Type With PHP

    Fonts on websites, like all other text characteristics, are manipulated using HTML. The font type, as well as its font family, color...

  • How to Compile a PHP File

    General-purpose PHP (Hypertext Preprocessor) is a scripting language that was intended for dynamic Web development. PHP code is saved into a PHP...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!