Utilizing Code Snippets with The Hub | GoDaddy Professional

Saving time with code snippets

Operating your ecommerce retailer, buying membership, on-line affiliation, eLearning website, and even only a easy web site that tells individuals about what you are promoting requires code. That’s simply the best way the web works. Because you may not be a programmer, likelihood is you may have leveraged a content material administration system, or CMS, like WordPress to do the heavy lifting.

Most CMS web sites can benefit from a plethora of plugin choices, coded by seasoned builders, to sort out most characteristic wants that will come up. Nonetheless, there’ll nonetheless be instances when it’s essential to add just a bit little bit of code to make a fast textual content change, run a easy report, or evaluate some database info.

For this, you’ll have to depend on what’s referred to as code snippets.

What are code snippets?

Code snippets are bite-sized chunks of code that, ideally, serve a single goal. With every change you need to allow or motion you need to take, you’ll write (or have a developer write) a brand new code snippet.

How do code snippets assist web site improvement?

Web site improvement begins with an thought and, with correct upkeep, continues indefinitely. Code snippets are helpful all through all the improvement course of to check concepts, make fast modifications, and run ongoing reviews. Within the subsequent couple of sections, we’ll share the right way to arrange code snippets and supply some useful examples.

Bear in mind, these are run with out the must be logged into the web site, so anybody from the developer to the shop proprietor, to an intern, may have the ability to help with the web site’s improvement!

How do you utilize GoDaddy Professional’s code snippets?

Utilizing The Hub by GoDaddy Professional means that you can add and run code snippets with out logging into your (or your shoppers’) websites straight. As soon as logged into The Hub, make it possible for the location is added to your record of web sites you handle.

Navigating to your website, you’ll discover a listing of menu decisions. Hovering over the one labeled Misc will reveal the Code Snippets choice for this website. (You may as well share snippets throughout your websites, however we’ll get to that in a minute.)

You’ll be introduced with a code window the place your snippet could be added and run. Relying on the kind of the present website, it’s possible you’ll be introduced with a pattern snippet. The instance proven right here pertains to a WordPress website and, when run, exhibits a listing of the put in plugins.

code snippets 2 hub

Have a code snippet that you just need to reuse throughout a number of websites? You’re coated there, too! Ensure to hit Save to give it a reputation and it’ll be added to your library of saved snippets — which you’ll entry from any of your websites’ Code Snippets interface.

Methods to use code snippets in WordPress

Managing your WordPress websites could be a lot simpler with the usage of code snippets. Listed below are simply a few snippets you would possibly discover helpful on your WordPress web sites.

Record your energetic plugins

One of many pre-bundled snippets will current you with a listing of a website’s put in plugins, however you might also need to evaluate that to which of them are actually energetic. Utilizing WordPress’ built-in “get_options()” perform, you may simply generate a listing of energetic plugins.


$active_plugins = get_option('active_plugins');

foreach($active_plugins as $plugin) {
echo $plugin."n";


Clear the WordPress object cache

Generally you simply know that your website just isn’t fairly exhibiting what it needs to be. There’s an opportunity that the WordPress object cache has some knowledge saved that must be cleared. There are a number of methods to do that, however now you may clear them with GoDaddy Professional Code Snippets!


echo ( wp_cache_flush() ) ? 'Cache efficiently cleared.' : 'Please strive once more.';


Utilizing the WordPress “wp_cache_flush()” perform, you may clear these cache hiccups shortly with out even logging into the location!

Be aware that snippets added to The Hub are executed solely when Run is pressed and don’t persist. They’re additionally not injected into WordPress’ filter and motion hook system. For these options, we might suggest the free Code Snippets plugin, which must be put in on every website individually.

Different utility snippets

One other advantage of utilizing GoDaddy Professional’s Code Snippets is that it simply works — even when your website just isn’t a WordPress website. Under are a few examples of different utility code snippets that you should use with any website, courtesy ManageWP.

Examine free area in your server

Server assets can refill shortly lately with the onset of extra video content material and high-resolution imagery. Keeping track of your server’s free area is vital for efficiency, scalability, and managing prices. This snippet returns the free area in your server, so that you don’t should log into your management panel to seek out out.


$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$base = 1024;
$class = min((int)log($bytes , $base) , depend($si_prefix) - 1);
echo sprintf('{b02bdf04de3f9bc06c998e855c65941e7d8f5cd012e86469a83340818e6b6d52}1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];


View contents of a file

Checking to ensure the contents of a file are what you anticipate could be helpful at instances. With a easy code snippet, you may return all the code of a file in your server. Be aware: be sure to replace the snippet to incorporate the total path to your file.


echo `cat ./index.php`;


Save time with Code Snippets from GoDaddy Professional

Logging into and out of web sites to make minor modifications, replace options, and collect info is extraordinarily time consuming. With The Hub by GoDaddy Professional and Code Snippets, you may handle much more than simply plugin updates with out logging into your websites — although you are able to do that too!

The subsequent time it’s essential to examine a server’s free area or clear WordPress caches, make sure you try GoDaddy Professional Code Snippets. Bonus factors when you save these snippets and reuse them for a number of websites!

Source link