What are some common pitfalls when using the header() function in PHP for page redirection, especially when working with external systems like Wordpress?

One common pitfall when using the header() function for page redirection in PHP, especially when working with external systems like Wordpress, is that headers must be sent before any output is displayed. To avoid "header already sent" errors, make sure there is no whitespace or HTML output before the header() function is called.

<?php
ob_start(); // Start output buffering

// Your PHP code here

header('Location: http://example.com'); // Perform the redirection

ob_end_flush(); // Flush the output buffer
?>