Saturday, 28 December 2013

How to Put Google Adsense Below Post Title in Wordpress?

In this article, we have to learn how to put google adsense ads below post title in wordpress without using any plugin.

For this purpose, we have to add widget placeholder to below post title. So first we have to register widget placeholder. To register widget placeholder add below code to functions.php (Wordpress Deshboard =>Appearance => Editor => Find functions.php file) file.

[code]

/********* Function to Register Widget Placeholder **********/
if ( function_exists('register_sidebar') ) {

/********* Adsense Widget Placeholder Registration **********/

register_sidebar(array('name'=>'Adsense Below Title',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
}

[/code]

After adding above code you can able to see this Widget Placeholder (name as "Adsense Below Title") appear in Widget area. For go to Widget area go to Wordpress Deshboard then Appearance -> click Widget.

So you can add Wordpress built in widget "Text" to add adsense code then add Text widget to "Adsense Below Title" Widget placeholder.

adsense ads widget

Now we have to place this widget placeholder to below post title. To do this, go to Wordpress Deshboard then go to Appearance and click Editor. Now find single.php file and find below code.

[code]

<?php the_title(); ?>

[/code]

After above code place below code.

<?php if ( ! dynamic_sidebar( 'Adsense Below Title' )) : ?>
<?php endif; ?>

So combine above two code look like this.

[code]

<h2><?php the_title(); ?></h2>
<?php if ( ! dynamic_sidebar( 'Adsense Below Title' )) : ?>
<?php endif; ?>

[/code]

 Done!

No comments:

Post a Comment