CodeIn House

  • Laravel
  • WordPress
  • jQuery
  • Javascript
  • Contact
Home   WordPress   How to Add Widget Area in Top of Most Recent Post in WordPre ...

How to Add Widget Area in Top of Most Recent Post in WordPress & Genesis Without Plugin ?

February 9, 2017 by SNK

add widget area below post title in genesis

In this tutorial we are going to create new widget area in most recent post below title in WordPress and in genesis.

This helps WordPress users to keep the static image or mostly use adsense code to display the largest leader board banner which looks elegant in your blog for ads.

I have not yet integrated adsense in my blog but i have already kept the widget area to manage them later so it could be more easy for me to just drag and drop the adsense codes into the specified widget area.

Lets get Started.

What we are going to do ?

  1. Register new widget area named as after post title.
  2. Set the Widget area below post title so that whenever we keep anything inside widget, it will displays them below post title in our theme.

Part 1 : ( For Genesis Users Only )

Step 1:-

Register new widget area. Open your functions.php file and write this code at the end of it. :-

PHP
1
2
3
4
5
6
//* Add  After Post Title Widget
genesis_register_sidebar( array(
'id'                => 'ad-after-post-title',
'name'          => __( 'Ad After Title', 'custom' ),
'description'   => __( 'This is Ad section under post title', 'custom' ),
) );

Step 2 :-

Set  this new widget area below post title.

functions.php
PHP
1
2
3
4
5
6
7
8
9
10
//* Show ads below post title on posts
add_action( 'genesis_entry_header', 'cih_post_after_title', 12 );
function cih_post_after_title() {
global $wp_query;
if ( is_single() && is_active_sidebar( 'ad-after-post-title' ) || (is_home() && is_active_sidebar('ad-after-post-title') ) && $wp_query->current_post == 0  ){
echo '&nbsp; <div class="ad-after-post-title">';
dynamic_sidebar( 'ad-after-post-title' );
echo '</div>';
}
}

Thats it, now if you drag and drop new widgets into your newly created widget area, it will display below post title.

Put your own adsense ads or your custom ads, just drag and drop and keep your ads.  These ads will show in single page as well as recent post in homepage.

If you want to remove from homepage just remove the line :-

functions.php
PHP
1
(is_home() && is_active_sidebar('ad-after-post-title')

This will remove the widget area from the most recent post on homepage and just show in single page only.

part 2 :- ( For Normal WordPress themes )

step 1 :-

Step 1 is same. Just copy code from above or if you want to know more rely in WordPress documentation on wordpress.org.

Step 2:-

Lets first display widget area below title in your single post only. Find your post page called single.php and open it. Find your post loop and enter these codes just below the the_title();

single.php
PHP
1
2
3
4
5
6
global $wp_query;
if ( is_single() && is_active_sidebar( 'ad-after-post-title' )){
echo '<div class="ad-after-post-title">';
dynamic_sidebar( 'ad-after-post-title' );
echo '</div>';
}

Step 3 :-

Now same goes for index.php as well, open up and add this line of code just below the the_title(); in your post loop to display widget area in most recent post in homepage.

index.php
PHP
1
2
3
4
5
6
global $wp_query;
if(is_home() && is_active_sidebar('ad-after-title') ) && $wp_query->current_post == 0  ){
echo '<div class="ad-after-post-title">';
dynamic_sidebar( 'ad-after-post-title' );
echo '</div>';
}

If you have any problem. Feel free to leave via comments section.

SHARE ON
Buffer

Enjoyed this article?

Like us on

WordPress add widget after post title in genesis post title widet widget area after post title

Avatar for SNK

About SNK

Hello Welcome to my Blog. I develop Websites Using Laravel Framwork & WordPress. Get Latest updates on Facebook | Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Connected !! With Us

TOP POSTS

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

TUTORIALS TILL DATE

  • September 2022 (6)
  • June 2021 (7)
  • October 2020 (5)
  • September 2020 (6)
  • September 2018 (14)
  • August 2018 (3)
  • July 2018 (4)
  • March 2018 (8)
  • February 2018 (5)
  • January 2018 (1)
  • December 2017 (2)
  • August 2017 (8)
  • May 2017 (1)
  • April 2017 (1)
  • March 2017 (4)
  • February 2017 (3)
  • January 2017 (4)

CATEGORIES

  • Angular (2)
  • CSS3 (3)
  • D3 (3)
  • HTML5 (7)
  • JAVA (11)
  • Javascript (20)
  • jQuery (8)
  • Laravel (35)
  • Others (3)
  • PHP (11)
  • Spring (2)
  • WordPress (10)

Top Categories

  • Angular
  • CSS3
  • D3
  • HTML5
  • JAVA
  • Javascript
  • jQuery
  • Laravel
  • Others
  • PHP
  • Spring
  • WordPress

Get in Touch

DMCA.com Protection Status

Recent Articles

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

© 2012-22 CodeIn House.  •  All Rights Reserved.