How to change a text dynamically in wordpress using php?

Problem: You need to change the text of something in WordPress but cannot figure out where to change it or it’s simply not possible to change it using the theme options.

The following code snippet will help you change any text dynamically using PHP.

  1. Copy the code snippet in functions.php
  2. Replace ‘ORIGINALTEXT’ by whatever text you want to change on your website.
  3. Finally replace ‘New Text’ by whatever you want and save.
  4. Important to note that the text you will replace is case sensitive
function start_modify_html() {

function end_modify_html() {

$html = ob_get_clean();
$html = str_replace( 'ORIGINALTEXT', 'New Text', $html );
$html = str_replace( 'originaltext', 'New Text', $html );

echo $html;

add_action( 'wp_head', 'start_modify_html' );
add_action( 'wp_footer', 'end_modify_html' );


Leave a Comment

Your email address will not be published.

Scroll to Top

Choose your language