What are best practices for organizing PHP code within header and footer files to avoid header modification issues?

When organizing PHP code within header and footer files, it is best to separate the logic from the presentation by using include or require statements to include separate PHP files for different functionalities. This helps avoid header modification issues and makes the code more maintainable and reusable.

// header.php
<!DOCTYPE html>
<html>
<head>
    <title>My Website</title>
</head>
<body>
    <?php include 'nav.php'; ?>
```

```php
// footer.php
    <?php include 'footer_content.php'; ?>
</body>
</html>