A fresh mix of code snippets and tutorials

Replace content in WordPress header.php

Here’s how to filter content in WordPress’ header.php template file using PHP.

Just edit the path to your theme’s header.php file, and modify the str_replace() parameters to match and replace the target content.

<?php // Replace content in WordPress header.php
// @ https://wp-mix.com/replace-content-wordpress-header/

include '/path/to/httpdocs/wp-content/themes/yourtheme/header.php'; // PATH
$data = ob_get_clean();
$data = str_replace('<title>wp-mix.com</title>', '<title>wp-mix.com : more</title>', $data); // REGEX
echo $data; 


In this example we’re using <title>wp-mix.com</title> to find all instances of <title>wp-mix.com : more</title> and replace each with . May be useful for other WordPress theme files as well. Have phun!

Learn more

WordPress Themes In Depth