Category Archives: Wordpress

Google Adsense for Wordpres – No Plugin Needed

Adding Google Adsense ads to your your WordPress blog was a tedious task. Either you needed to manually modify your theme, or you had to use a plugin, such as Google’s own Adsense plugin. Even then, placements were limited and handling both mobile and desktop themes was complicated at best. Recently, two things have changed: Google retired the Adsense plugin and introduced Auto Ads.

At first, the situation seemed like it turned for the worse. Without the official plugin, you had to resort into using a third-party plugin or manually placing ads in your theme. But Auto ads made things much simpler. Instead of having to manually place your ads, you can let Google do it for you. It works great on both desktop and mobile theme.

The easiest way to enable Auto ads is using a child theme. First, you need to get the Auto ads ad code. Nextg, in your child theme’s functions.php add the following lines, making sure to replace the javascript snippet with your own one.

// Add Google Adsense
function my_google_adsense_header() {
?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-4066984350135216",
          enable_page_level_ads: true
     });
</script>
<?php
}
add_action( 'wp_head', 'my_google_adsense_header');

Google Analytics for WordPress

To set up Google Analytics tracking for WordPress you don’t need any third-party plugin. It can be easily done using a child theme. A child theme, is a code that modifies the current theme in a way that won’t interfere with future upgrades. To enable Google Analytics, start by creating a child theme using the official documentation.

Now, you need to get you Google Analytics tracking code. Over the years the tracking code had a few different versions. You should make sure you are getting the latest tracking code, which currently looks like:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-380837-9"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-380837-9');
</script>

To get the tracking code, follow the instructions on this page.

Now we add the tracking code to each page using the child theme. In your child theme’s directory, edit the functions.php file and add the following lines. Replace the tracking code with the one you acquired.

// Add Google Analytics tracking
function my_google_analytics_header() {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-380837-9"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-380837-9');
</script>
<?php
}
add_action( 'wp_head', 'my_google_analytics_header');

This adds the tracking code to the <head> of every page.

Dealing with Spam – Follow-up

In the beginning of June, I wrote about the rising number of spam missed by Akismet. The main issue was a noticeable increase in the number of spam messages which get through Akismet, which is kind of the de-facto spam filtering for WordPress. Twice a day, on avearage, I had to manually mark comments as spam, which really got under my skin. After writing that post, I’ve looked at a number of solutions.
Continue reading

Something gone wrong with Akismet?

Akismet is a great spam filtering service for WordPress which did wonders for my blog. Actually, it’s quite generic and can be used with any commenting service, for example with Trac (I used this for Open Yahtzee’s Trac before reverting back to SourceForge new ticket system). For a long time, Akismet allowed me to blog and not worry much about spam, as it hardly missed – usually less than 5 missed spams a month. But something went wrong in the last three months as can be seen in this chart:

spam_chart

As you can see, the number of missed spam increased rapidly from February to May (more than 15-fold) while the number of overall spam messages decreased. I have to manually mark the missed spam and I really can’t say why some of them are missed. They are spammy as always and surely not unique in any sense.

Although it’s not a deluge of missed spam, I really don’t like dealing with, so I consider adding CAPTCHA to supplement Akismet. This will also help with my backups, because Akismet keeps all the spam messages it flags 15 days, which means that unfortunately I backup more than 20000 spam messages each week (hopefully, one day I’ll find good use for it).

Has something gone wrong with Akismet? Do you experience the same problems?

Incremental WordPress Backups using Duply (Duplicity)

This post outlines how to create encrypted incremental backups for WordPress using duplicity and duply. The general method, as you will see is pretty generic, and I’ve been using it successfully to backup also Django sites and MediaWiki installations. You can use this method to make secure backups to almost any kind of service imagineable: ftp, sftp, Amazon S3, rsync, Rackspace Open Cloud, Ubuntu One, Google Drive and whatever else you can think about (as long as the duplicity folks implemented :-)). If you prefer a simpler solution, and don’t care about incremental or encrypted backups, see my Improved FTP Backup for WordPress or my WordPress Backup to Amazon S3 Script.
Continue reading

Improved FTP Backup for WordPress

This script backups both the database and files of a WordPress blog into a remote FTP server (while keeping a local copy). It’s an update of my WordPress Backup to FTP script. The main changes are auto-detecting database settings and better support for caching plugins (specifically WP-Cache). The new version makes it easier to backup multiple WordPress blogs to the same FTP server.
Continue reading

Sociable Plugin Doesn’t Play Nice

I’ve been using the Sociable plugin for adding easy “share” links to the bottom of my posts. Up until yesterday I’ve been using the 2.x versions of the plugin, but yesterday I’ve upgraded to 3.4.4. Today I’ve noticed to my surprise that the plugin automatically adds a box to my admin dashboard with “The Latest news from Yoast”, Yoast beeing the plugin’s maintainer, Joost de Valk, blog. The plugin itself doesn’t feature any way to completely disable this “feature”. One has to hide it using the dashboard settings. While this may seems benign, in my opinion its pushing the limit. If I’m interested in getting updates from that blog, I would sign up to its RSS feed. I don’t like getting “free” functionality not advertised in the plugin description.

I must add that as a user of the Sociable plugin, I’m more than satisfied. I probably won’t stop using the plugin just because of this issue, but it still seems to me like improper manners.

WordPress Backup to FTP

Update: A newer version of the script is available.

This script allows you to easily backup your WordPress blog to an FTP server. It’s actually a modification of my WordPress Backup to Amazon S3 Script, but instead of saving the backup to Amazon S3 it uploads it to an FTP server. Another update is that now the SQL dump includes the database creation instructions so you don’t need to create it manually before restoring from the backup.

Although I’ve written it with WordPress in mind (to creates backups of my blog), it isn’t WordPress specific. It can be used to backup any website that consists of a MySQL database and files. I’ve successfully used it to backup MediaWiki installation.
Continue reading