How to Paste Snippets From Web Into WordPress Website?

WordPress is a huge platform that enhances the user’s ability to improve website performance. Playing with codes and modifying the website is a handy task for experts. But for beginners, this is going to be a bit tricky. If you are new to WordPress and you have a task to make the changes in coding, learn how to paste snippets from web into WordPress then this blog contains some useful tips and information to do this task easily.

Apart from all these things, WordPress is the easiest and best content management system. Hence it has been used worldwide to manage and customize the website exactly the way developers want.

Reasons to Paste Snippets From Web Into WordPress?

Adding code snippets to your site is one of the easiest ways to extend your website’s features. No doubt installing a plugin is the obvious way to enhance the built-in features of WordPress.

When it comes to non-developers, it’s hard to find a plugin that addresses your needs appropriately. On the other hand, you can find hundreds of WordPress tutorials on the web that recommend adding code snippets to meet your needs.

Expanding the functionality of your website while improving your workflow with code snippets is possible, but adding them to your functions.php file could cause trouble. The Code Snippets plugin makes it easier to incorporate and manage them.

Five reasons to use code snippets in your WordPress development include:

  • To remove default widgets from client sites.
  • For protection against malicious attacks.
  • So you can automatically email contributors when publishing their posts.
  • To prevent clients from deactivating specific plugins.
  • If you want to change the default Gravatar.

How to Paste Snippets From Web Into WordPress?

Let’s break down this tutorial into 2 different sections:

  • Customizing WordPress template files
  • Customizing functions.php file

Moving on…

Customizing WordPress Template Files

Before we dive in, let’s take a look at what a WordPress template file is.

wordpress template file

Every WordPress theme is made up of template files, which define how your website is displayed on the front end. For example, header.php is a default template used in most WordPress themes to define the header area of your website pages.

Insert Snippets Into Any Template File

You can insert code snippets into any template file, such as functions.php, single.php, etc. by either using a child theme or adding the code directly to your existing parent theme.

However, it’s advised not to customize the template directly in your parent theme because, when you upgrade your theme, you’ll lose all the customizations you’ve made. To preserve the tweaks even after upgrading your theme, you might want to create a child theme and make customization within it.

A child theme is a WordPress theme that inherits its functionality from another WordPress theme (the parent theme). Using a child theme is the right choice if you want to make a lot of tweaks to your template files.

Let’s take a look at how to create a child theme and insert snippets into your template file.

Create Child Theme By Customizing functions.php File

functions.php is a template file in your WordPress theme that enables you to easily extend the features of your theme and WordPress installation. To extend the features, all you have to do is get some code snippets from web and paste them into your functions.php file in WordPress.

functions.php file to edit wordpress template

Just like any other template file, you can add snippets directly to your functions.php file. In addition, to retain the customization even after upgrading your theme, you can create a child theme and insert the code within it.

However, the downside is that you’ll lose all the customization you’ve made on a child theme if you switch over to a new/different theme. This is where a site-specific plugin comes in.

A site-specific WordPress plugin is independent of your theme, which allows you to add custom snippets to your site. You can use the site-specific plugin in 2 ways:

  • Using a ready-made plugin, such as Code Snippets
  • Manually creating a site-specific plugin

Using Readymade Plugin – Code Snippets

Code Snippets is a WordPress plugin that provides a graphical interface for managing snippets similar to the Plugins menu.

It removes the need to insert custom snippets to your theme’s functions.php file. Since you’re not inserting the code in any theme files, you can preserve the customization on your site even after switching your theme.

With Code Snippets, you can activate or deactivate snippets, just like plugins.

To add a custom code snippet, go to Snippets » Add New and then copy the snippet to the Code field.

how to use code snippets plugin to paste codes into wordpress from web

Make sure to specify a title, description, and tags for your snippet as a reference for yourself down the line. Once done, click Save Changes and Activate.

To manage your snippets, you can click on the All Snippets menu. Here, you can activate or deactivate the snippets, just like WordPress plugins.

Create Site-Specific Plugin & Insert The Code

You can manually create a site-specific plugin and insert the code within it. Unlike a ready-made plugin, a manually-created site-specific plugin is usually a basic, lightweight plugin that doesn’t have a graphical interface for managing snippets.

Create Site-Specific Plugin

  • Open a text editor on your computer, such as Notepad or TextEdit. Your plugin file needs a specific header code so that WordPress can recognize it as a plugin. Copy the following header code to your Notepad:
>?php
?*
Plugin Name: site plugin for example.com
Description: site specific code changes for example.com
*/
/* start adding funtions below this line*/

/* Stop adding funtions below this line*/
?>
  • Let’s name your site-specific plugin file custom-snippets.php. Bear in mind that in order to save your file as a PHP file, you’ll need to choose All Files as your Save as type.
  • Now create a new folder named custom-snippets and move the PHP file you’ve just created to the folder.
  • Next, you’ll need to compress your site-specific plugin folder, custom-snippets. Here’s how to do it:
  • Windows users can right-click on the folder and then click Send to » Compressed (zipped) folder.
  • If you’re on Mac, right click and select Compress “custom-snippets”.

Install Site-Specific Plugin

You can upload the file via FTP or you can use the WordPress “Upload Plugin” button. WordPress “Upload Plugin” button is a very easy method. If there is any problem or error coming, you can use the FTP method. If you don’t know how to use FTP to upload files, we have a detailed guide.

  • Now that you have created the plugin’s zip file, go to your WordPress dashboard and upload it by navigating to Plugins » Add New. Then click Upload Plugin. You’ll now be prompted to choose the correct plugin file and install it.
upload site specific plugin on wordpress to paste snippet codes from web
  • After installing the plugin, go ahead and activate it so you can start using the site-specific plugin.

Using Site-Specific Plugin

  • In order to add a snippet to your recently uploaded site-specific plugin, go to Plugins » Editor. On the right-hand side, you’ll see a dropdown menu Select plugin to edit. Let’s choose Custom Snippet and then click Select. You’ll now be directed to the custom-snippets.php file of your plugin.
add code snippets to site specific plugin
  • Here, you can add the snippet of your choice below the line: /* Start Adding Functions Below this Line */
  • After inserting your snippet, click on Update File.

That’s it!

We hope this guide helped you add code snippets to your WordPress site.

Now, go ahead and find some code snippets that you can add to enhance your WordPress functionalities.

Paste Snippets From Web Into WordPress Easily!!!

As we have just seen, there are a few ways to add custom code to your WordPress website, but not all of them are actually productive in the long run. For example, for theme-specific changes (looks & feel of the website), add custom code to the functions.php file. For any other changes, ideally, you should have your custom site-specific plugin

Just make sure that you add custom code to WordPress in a way that’s safe, and makes it easy to debug if something goes wrong. I hope this article helped you learn how to paste snippets from web into WordPress sites easily.

Leave a Reply

Your email address will not be published.