Your slogan goes here

How to Add Google Analytics 4 to WordPress (And What Is GA4 Anyway?)

Google has big hopes for its Google Analytics version 4. In fact, it calls it “the next generation of Google Analytics” – their own words. To say the least, Google Analytics 4 is (going to be) a big deal! It’s probably a good idea not to miss the bandwagon and learn how to add Google Analytics 4 to WordPress today.

In this guide, we will tell you what Google Analytics 4 is and how it is different from the previous edition of Google Analytics – called Universal Analytics. Then, we’re going to show you how to enable it on your WordPress website.

Google Analytics 4 – what it is 

Google Analytics seems like a product that worked perfectly well and was probably complicated enough already, right? Who needs a new version?! 🤷‍♂️

The long story short is that v4 is Google’s answer to the ever-increasing popularity of mobile and the need for a more flexible way of collecting data.

The way things used to work with Universal Analytics (UA) all happened around pageviews. GA4, on the other hand, is based on events. Moreover, with this new version of Google Analytics, you can track not only a website but also an app that you might have alongside your website.

Apart from that, Google Analytics 4 also has its own new spin on reports and report looks. Among them: a new home report, real-time report, games reporting, monetization reports, and more.

Overall, Google Analytics 4 is the next step for analytics – a more modern and optimized solution.

However, there are some limitations of Google Analytics 4 to be aware of. Mainly, GA4 doesn’t yet connect to the Search Console (or other Google products), and there’s no cross-domain tracking possible. If you’re using WooCommerce, tracking your sales metrics (like conversions) also doesn’t work (yet).

“Will I lose my current Google Analytics panel after I switch?”

The good news is that you don’t have to lose any sleep over it at this point. In this early stage of Google Analytics 4’s adoption, you can run both Universal Analytics and Google Analytics 4 simultaneously.

How to get started with Google Analytics 4

Here’s the kicker, the recommended way of setting your site up with Google Analytics 4 is to run it alongside UA and not instead of it.

Just to emphasize this again, in the recommended setup, you’re going to be running both UA and GA4 at the same time – at least for now. As GA4 matures, we might see UA go away, but that’s not where we’re at yet.

Here’s how to set up Google Analytics 4 and then integrate it with your WordPress website:

1. Sign up to Google Analytics

How to Create a Universal Analytics Property (when GA4 is the default)?

Even though Google Analytics 4 is now the default version for all newly created properties in Google Analytics, some users might still want to create properties of older versions (Universal Analytics).

Even though Google has made that option a bit more hidden, it’s still possible. In this quick blog post, I’ll show how to create Universal Analytics properties in Google Tag Manager (when the default version is Google Analytics 4).

How to Install Akaunting Accounting Software on Ubuntu 20.04

Written in PHP, Akaunting is a feature-rich and open-source online accounting software that allows users to manage finances and keep track of all the invoices, payments, and expenses, to mention just but a few of the financial-related tasks.

It’s an ideal online accounting platform for small businesses that do not have the financial wherewithal to procure pricey accounting software. Akaunting provides an elegant and intuitive UI will all the features and controls needed to stay abreast of your cashflows and transactions.

Akaunting Features

Notable features include:

  • Multi-currency support.
  • Visual reporting using graphs.
  • Vendor management system.
  • Ability to send invoices to clients via the SMTP protocol (Requires a mail server configured on your server).
  • Creation and management of bills, invoices, and other payments for jobs in progress.
  • Ability to accept bulk payments.
  • Discount management system.
  • Customer Summary.

In this guide, we will walk you through the installation of Akaunting self-hosted free Accounting software on Ubuntu 20.04.

How To Require a Featured Image Before You Can Publish a Post

Are you looking for a way to require a featured image before you can publish a post? This snippet will require that you have added a featured image before your post can be published. If you try to publish a post without a featured image after adding this snippet, you will receive this message: “You must select Featured Image. Your Post is saved but it can not be published.”


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_action('save_post', 'wpds_check_thumbnail');
add_action('admin_notices', 'wpds_thumbnail_error');
function wpds_check_thumbnail($post_id) {
// change to any custom post type 
if(get_post_type($post_id) != 'post')
if ( !has_post_thumbnail( $post_id ) ) {
// set a transient to show the users an admin message
set_transient( "has_post_thumbnail", "no" );
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'wpds_check_thumbnail');
// update the post set it to draft
wp_update_post(array('ID' => $post_id, 'post_status' => 'draft'));
add_action('save_post', 'wpds_check_thumbnail');
} else {
delete_transient( "has_post_thumbnail" );
function wpds_thumbnail_error()
// check if the transient is set, and display the error message
if ( get_transient( "has_post_thumbnail" ) == "no" ) {
echo "<div id='message' class='error'><p><strong>You must select Featured Image. Your Post is saved but it can not be published.</strong></p></div>";
delete_transient( "has_post_thumbnail" );

Setting a Fallback for Post Thumbnails in WordPress

One of the countless things that I love about WordPress is how easy and efficient the process of adding new content is. All you have to do is provide the art and copy and your theme will take care of the rest. While this workflow is usually smooth, there are times the end user can miss a step or two. I’ve noticed when working on larger sites with multiple authors one of the most common things to slip through the cracks is setting a featured image. While this shouldn’t break your theme, it can create layout inconsistencies or (shudder) broken images. Lucky for us, we can easily provide a fallback, and I’ll tell you how.

WordPress Post Thumbnails

Post Thumbnails were introduced in WordPress 2.9 [Source: WordPress Codex] and have since become somewhat of a standard for theme developers. If a theme declares support for this functionality, it allows authors to set an image that will represent Posts, Pages, or Custom Post Types. How this image is utilized is completely dependent on the theme. A lot of themes will use a featured image to accompany excerpts, but that’s just one example.

Setting A Fallback

If your theme uses Post Thumbnails, it is probably wise to set a backup. That way if you (or one of your authors) forgets to set a featured image before publishing a post it will not break the layout. One way to do this is by grabbing the first image from the post, and returning it if no post thumbnail exists. First, add the following to your functions.php:

//Call the first uploaded image in the post
function fallback_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment
if($files) :
$keys = array_reverse(array_keys($files));
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'thumbnail', true); //Set your image size and crop to true or false here
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
print "<img class='featured' alt='$the_title' src='$fallback' />";

Now, determine where in your theme the featured image is used (Hint: Check index.php, loop.php, home.php, etc.). Look for the call to get_the_post_thumbnail and replace it with the following:

<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { //If a featured image was set, return it
echo get_the_post_thumbnail($post->ID);
} else { //If it wasn't set, return the fallback
echo fallback_image();
} ?>

Note: I am assuming that your theme has already established support for Post Thumbnails. If it hasn’t you’ll need to add that functionality. Don’t worry, it’s easy. Just look to the Codex to learn how to enable support for Post Thumbnails.


This is just one way you can handle fallbacks for featured images. I have seen a lot of themes let allow you set a single default image, a company logo for example, as a fallback and that seems to work perfectly fine as well. The decision is ultimately up to you.

15 Tips for Using Google Search Console to Effectively Grow Your Website Traffic

Google Search Console is a powerful free tool created by Google to help website owners understand how Google sees their website. Unfortunately, most businesses don’t know how to effectively use the full power of Google Search Console to increase their website traffic. In this article, we will show you how to properly use Google Search Console to improve your website SEO and get more visitors.

What is Google Search Console?

Google Search Console is a free tool offered by Google to help website owners monitor and maintain their site’s presence in Google search results.

It provides essential marketing data that you need to start tracking from day one. It also alerts you about errors, security issues, and indexing problems that may affect your website’s search rankings.

You can use all this information in your WordPress SEO strategy to increase your website traffic.

The sad part is that most businesses don’t utilize the full power of Google Search Console because majority of them think that just adding their website to Google Search Console is enough.

There’s so much more that you can be doing.

If you’re not leveraging all of the powerful features that Google Search Console offers, then you’re missing out.

Luckily, we’re here to help. We have created this ultimate Google Search Console guide to help you grow your website like a Pro.

Note: Since this is a comprehensive guide, we have added a table of contents for easier navigation.
« Older posts

© 2021 dev

Theme by Anders NorenUp ↑