How to add a custom filter or function with Code Snippets

The best way to add a custom PHP function or filter to your site is through the code snippets plugin. This has some benefits over a child theme in that you can better organize the code you are adding. Enable and disable snippets with a click, export and import, and more. Even some nice protections in place to prevent you from breaking your site, and if you do break your site there are some easy ways to re-access and fix your code.

You can download the Code Snippets plugin by going to your WordPress admin and clicking plugins > add new. Then searching for Code Snippets.

Once activated you can navigate to Code Snippets in your admin menu. When installed Code Snippets provides a couple of example snippets that you can use to edit and see how things work.

If you want to learn more about the plugin and it’s available settings check out it’s WordPress plugin page.

Code Snippet Example, changing the logo link for your site

For a quick example of building a code snippet you can click add new in the code snippet area and then add in your code into the code area.

Lets say you wanted to change the logo link to something other then your sites home url. For that you can use this snippet:

add_filter( 'kadence_logo_url', 'custom_logo_url' );
function custom_logo_url( $url ) {
	$url = '';
	return $url;

You would place that in the code area and then add a quick description below. Because this is only effecting the front end of the site I selected “Only run on site front-end”.

Save changes and activate and you are set!