In this video post I want to show you how to add code snippets the easy way to your WordPress site.
You’ve probably seen recommendations to add code to your functions.php file to fix an errors on your site, to add functionality or to make a change of some sort.
You will be presented with a wall of php code and you are told to add this to your functions.php file. All well and good if you are a developer but what if you are not that technical and don’t want to mess with code files.
There are some issues with “simply adding code to functions.php”, here is what you need to be aware of:
- If there are errors in the code, you can crash your site.
- When you change your theme the code also needs to be migrated.
- A site with lots of snippets can become a pain to manage and remember what each piece of code does
Video Demo – How To Add WordPress Code Snippets The Easy Way
In this demo I’ll show you how to use this plugin to add code
The Plugin
Here’s a link to the plugin I used
https://en-gb.wordpress.org/plugins/code-snippets/
The Code Snippet
And if you want to change your add to cart button to buy now, here is the code.
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
Wrap Up – How To Add WordPress Code Snippets The Easy Way
To wrap up this plugin is great when you are developing a site and need to manage lots of custom code, and not have it break your site during testing.
A highly customised site with lots of snippets can become messy when a few months later you cannot remember what each piece of code does, so descriptions and tagging make things much easier to maintain.
If you are still not happy adding custom code to your WordPress site you can always hire me to do it for you.
Photo by Alexander Sinn on Unsplash