Category Archives: WordPress

Google Ads placement In WordPress Sidebar

Google AdSense Ad Units options

Writing articles and maintaining a website takes some time and is not exactly free. If you want to start monetizing your WordPress website you could use Google AdSense and place Google Ads in your website or mobile app.

There are a few steps until you can manage to show ads on your websites. Let’s get started:

AdSense Account Activation

First thing we need is to create a Google AdSense account. This is the place from where we obtain our Google Ads. Start by signing into https://www.google.com/adsense and init the account activation process. This usually takes between 3-10hours but it depends on your account and website.

You’ll be sent an approval email so soon as you receive it you’re good to go.

Ad Unit Creation

Google AdSense Menu

Head to AdSense webpage again and hit Ads->Ad units.

Each zone of the website where any ad will appear should have a dedicated ad unit.


We’re going to create an ad for the sidebar so choose Text & display ads. Enter an unique id for your add which can be something like WEBSITE_AD_SIDEBAR then click save.

You can now obtain the Ad Code which must be added into your website.


Placing Ads On Website Sidebar

How to create HTML Text Widget

Head to your Worpress Admin Menu.

Enter Appearance->Widgets.

Drag a new Custom HTML to your siderbar and fill the content with the exact Ad Code you get from AdSense.

Click Save!

And Voila, you know have Ads on your WordPress Sidebar.

How to create a basic Google Maps plugin for WordPress

There might be some WordPress plugins out there that could be used to add Google map to posts and pages. Still I didn’t find it necessary to install one when creating it is fun and easy.

Adding the final plugin to a post/page will be done using shortcode.

First of all you must create the plugin directory in wp-content/plugins/plugin_name.

Add two files here, the first an empty index.php and the second plugin_name.php

In order to be able to activate this plugin some basic details need to be added at the beginning:

/**
 * Plugin Name: Custom Google Maps
 * Plugin URI: http://catalinmunteanu.com
 * Description: Create Google Map element using a location query
 * Version: 1.0.0
 * Author: Catalin Munteanu
 * Author URI: http://catalinmunteanu.com
 */

Then we must create a function that will process this plugin’s shortcode:

 

function google_map_print($attrs, $content=null) {
    $item = shortcode_atts(
        array(
            'location' => null
        ),
        $attrs,
        'google-map'
    );

    $result = '<div>';
        $result .= '<iframe
            width="100%"
            height="250"
            scrolling="no" marginheight="0" marginwidth="0"
            frameborder="0" style="border:0"
            src="https://maps.google.com/maps?f=q&hl=en&geocode=&q='.$item['location'].'&aq=t&ie=UTF8&hq=&t=m&z=17&output=embed">
            </iframe>';
    $result .= '</div>';
    return $result;

}

add_shortcode('google-map', 'google_map_print');

 

That’s all. After you activate the plugin you can add it in your posts and pages using the shortcode:

[google-map location="Bucharest"]

Result: