How to Find and Replace The Text without plugins on WordPress Website


// Hook the function to run before the post content is displayed
add_filter('the_content', 'replace_text');

// Hook the function to run before the post title is displayed
add_filter('the_title', 'replace_text');

// Hook the function to run before other text is displayed (e.g., widgets, excerpts)
add_filter('widget_text_content', 'replace_text');
add_filter('the_excerpt', 'replace_text');
add_filter('wp_nav_menu', 'replace_text');

function replace_text($text) {
    // Replace "News" with "Update"
    $text = str_replace('News', 'Today', $text);

    // Replace "CNN" with "BlogsTour"
    $text = str_replace('CNN', 'BlogsTour', $text);

    return $text;
}

Leave a Comment

Your email address will not be published. Required fields are marked *