Documentation

Replacing a word, sentence or anything from your Html

Posted in: Getting Started (3) Plugin Options Explained (22) Actions / Filters (19) How To (5)   

The also support a visual interface module easier to use, please check with this instead Replace arbitrary words from page HTML through a visual interface module.

As default the plugin offer quite many options to control HTML data through the options. Giving the complexity of environment, sometime require specific functionality to achieve desired results.

There are multiple ways to make replacements within the outputted HTML, by making direct changes within the plugin/theme which produce the code block (obliviously not preferable as in majority will break update functionality), through plugin functionality extend (see Create a custom Module Component, extending the plugin functionality), or through filters wph/ob_start_callback which would be the easiest way.

In a scenario of using a custom WordPress plugin, let’s presume it output a sentence like Powered by WordPress so we need this replaced.

The easiest way would be to use wph/ob_start_callback filter along with a custom code. This should be placed wither within theme functions.php or within a custom plugin (see Simple plugin framework to be used along with Wp Hide filters / actions and functionality extend)


        add_filter( 'wph/ob_start_callback', 'custom_ob_start_callback' ); 
        function custom_ob_start_callback( $buffer )
            {
                
                $buffer =   str_replace("Powered by WordPress" , "", $buffer);
                
                return $buffer;
                   
            }

The above code use a simple str_replace to replace all occurrences of the search string “Powered by WordPress” with the replacement string, in our case an empty text.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Scroll to top