In-Browser Cryptomining is the latest and greatest way to monetize your website and now it’s super simple to add it to any WordPress site. If you went to the Plugin directory, you’d see there are already WordPress plugins for in-browser mining, but you would notice that the developer takes a cut of your profits! Today I will teach you how to write a super simple plugin to add an inbrowser Monero miner to your WordPress site completely free of 3rd party developer fees!

If you haven’t thought about the ethics or your legal responsibilities regarding using your site users CPU for mining, you might want to check out our article on In-Browser Mining. Nobody is really sure of the legal ramifications of using this software, so please install it at your own risk.

 

Step One: Get a Private Key

  1. Go to Coin-Hive and sign up for a free account – https://coin-hive.com/
  2. Sign into your new account
  3. Go to the Settings page
  4. Open the Sites & API Keys page
  5. Copy your Public Key. You will need it later in the tutorial

 

Step Two – Create the Plug-in

By building our code into a WordPress plugin, we make it super simple to inject our Javascript code without touching the core WordPress files, meaning there is no chance of breaking our website. It also means we aren’t messing around with our themes and you will be able to Enable/Disable your mining code with a simple click of the button.

 

  1. Download the plugin template here (23kb)
  2. Extract the zip file into a directory by itself. We will be adding your public key to one of the files.
  3. A more in-depth explanation of how the plugin works is provided below.
  4. Open the Public folder
  5. Open the JS folder.
  6. Open monero-miner-wp-public.js in a text editor.

 

 

  1. This is the function where we tell the miner to start working. You can see it already has a public key in the function call.
  2. Replace this key with the public key you got earlier from the Coin-Hive Sites & API Keys page.

 

  1. Save the file.
  2. Zip the files back up into a .zip file
  3. Open your WordPress Site and login to the admin dashboard.
  4. Scroll over the Plugins Menu bar and select Add New
  5. Click the Upload Plugin button

 

 

  1. Find the zip file you earlier and Upload and Activate.

  1. Done! Your Monero miner is now mining for you whenever somebody opens your website. You can test it is working by opening your Dashboard on Coin-Hive and watching the Hashes counter.

 

 

The Nuts & Bolts (Advanced users only)

 

nofee-monero-miner-wp.php

This file is the is the constructor for our WordPress Plugin. It contains the activate, deactivate and run functions required for WordPress plugins.  It also contains the WordPress function we use to include the Coin-Hive script.

 

Public folder

This folder contains all the public content for the plugin to display. The only part of this that we have modified is where we call the Activate miner function in the public/js/nofee-monero-miner-wp-public.js file.

Simple as that =)

 

 

If you are interested in investing in cryptocurrencies like Monero,  Bitcoin or others, you can find where they are listed at Where Can I Buy That Crypto or check out Coinspot.

 

Peter Law

View all posts