Support » Fixing WordPress » Insert widget area for ads above content below header in main content column

  • Hi,

    I’m trying to insert a widget to display Ads above the main content on my site (above post title and below header) on some of the main pages which include:

    Home Page
    Archive Page
    Single Post Pages
    Pages (except for main pages such as ‘contact-us’ etc)

    Again I only want this widget to show up once on each page (at the top below the
    header and above the first post title/content), and I only want it to show up in
    the main content column (left side which is the bigger content area of a 2 column site).

    I think I have successfully accomplished this but need some feedback to
    make sure I did it right or if there is a better way to do it.

    Below is the code that I have put into my child theme’s functions.php file:

    //* Register before post title widget area
    genesis_register_sidebar( array(
    	'id'            => 'before-post-title',
    	'name'          => __( 'before post title', 'eleven40' ),
    	'description'   => __( 'This is a widget area that can be placed before the post titles and below the header on main pages', 'eleven40' ),
    ) );
    
    //* Hook genesis before entry widget area before post title
    add_action( 'genesis_before_entry', 'sp_before_post_title_widget' );
    	function sp_before_post_title_widget() {
    	global $wp_query;
    	if ( is_singular( 'post' ) || is_page() && !is_page( 'contact-us' ) || ($wp_query->current_post == 0) && is_archive() || ($wp_query->current_post == 0) && is_home() )
    		genesis_widget_area( 'before-post-title', array(
    			'before' => '<div class="codeblocktop">Sponsored Links',
    			'after' => '</div>',
    	) );
    }

    This code has accomplished what I wanted it to, but I have some concerns that I would really appreciate help with…

    1.) Is the code correct?

    2.) Is there a cleaner piece of code that will accomplish the same thing?

    3.) Is there a better way to do this?

    Like I said… it’s working exactly how I want it to but just want to double check with folks who actually know what they’re doing and make sure that I did it right.

    Please forgive me as I am new to WordPress and learning as I go. I would
    appreciate any help you can give me. Thanks!

    P.S. My Child Theme: eleven40 (genesis framework)

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert widget area for ads above content below header in main content column’ is closed to new replies.