0

I am trying to insert two 125x125 ads into the comment section of a Genesis Child Theme -

Where I would love 2 ads

The screen above shows where I would want it but I am at a total loss on where to insert this overall. I have search for a code snippet for functions.php or even trying to figure which file (comments.php etc) to insert code into to make them show up.

Any help would be great appreciated.

2 Answers 2

1

I would use the Genesis Simple Hooks plugin which allows you to add code to Genesis Comment Form hook. I'm using Hostgator ads for this example, but adsense can be used too.

I dropped this code

<a href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=brilliantpamela-" style="float:right; margin: 4px 3px;"><img src="http://tracking.hostgator.com/img/Discount_Shared/Hostgator-new-_AN-125x125.gif" border="0"></a>

into

enter image description here

The simple hook action only allows you to place code above the comment. To place the ads with in and on the right of the form in your example, you'll have to float the ads to the right and add margins to space them out. I added:

style="float:right; margin: 4px 3px;"

Check out the example I made here: on a sample site

This can also be done without using the plugin and going into Genesis' comments.php.

Currently creating a tutorial at http://brilliantpamela.com/2013/08/31/how-to-insert-ads-in-genesis-comment-form/

1
  • Thanks for this, I am currently looking for a code solution though. I can't rely on plugins etc. I will keep an eye out on the post on the code solution. I don't think the comments.php files is truly what I need. Aug 31, 2013 at 22:49
1

These are the actions Genesis takes in the comment section:

do_action( 'genesis_before_comments' );
do_action( 'genesis_comments' );
do_action( 'genesis_after_comments' );

do_action( 'genesis_before_pings' );
do_action( 'genesis_pings' );
do_action( 'genesis_after_pings' );

do_action( 'genesis_before_comment_form' );
do_action( 'genesis_comment_form' );
do_action( 'genesis_after_comment_form' );

Genesis adds its comment form to the 'genesis_comment_form' action using a WordPress comment_form() call.

You can add your ad code before the form as Pamela points out in her answer. Without using Genesis Simple Hooks, use this code in your functions.php child theme file:

add_action( 'genesis_before_comment_form', 'wpse_112380_add_ads' );
/**
 * Add Google ads to comment form.
 */
function wpse_112380_add_ads() {
    // Add the ad markup here.
}

Then you can use CSS to move it where you want it.


This solution can be applied to any action in the Genesis Simple Hooks plugin. Once you have added your markup or code you can convert it to PHP like this:

add_action( 'genesis_action_hook', 'function_name' );
/**
 * Explain function here.
 */
function function_name() {
    // Add your PHP code here.
}

Change the values of genesis_action_hook and function_name to the action hook you are using and the function name to the unique function name you want to use. Function names should be unique to the current WordPress installation or PHP will throw a fatal error.

If you are just adding markup (no PHP), jump in and out of PHP before adding it.

function function_name() { ?>
    // Add your markup here.
<?php
}

This way you can test your additions in the plugin and then change it over to code after your done. It makes it a little easier to remember all those actions that Genesis adds and can speed up development. Just don't forget that there are other Genesis hooks that are not included in the plugin.

3
  • Thanks a ton charles for this. Now I need to figure out how to add the div correctly for it to fire. <div id="bsap_######" class="bsarocks bsap_#####"></div> Sep 3, 2013 at 19:08
  • before any styling this is what I have - glui.me/?i=4psr97881utabl8/2013-09-03_at_3.31_PM.png it just sits them to the left or the right of the comments section not IN it. What am I missing? Sep 3, 2013 at 19:30
  • 1
    You might ask the style question separately. Then a designer can answer you. Right now you're stuck with me and CSS hates me. :) Sep 4, 2013 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.