Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Adsense to the final Content Post
Tagged: adsense
- This topic has 9 replies, 2 voices, and was last updated 11 years ago by Brad Dalton.
-
AuthorPosts
-
April 17, 2013 at 2:35 am #35909ManuelMember
Hi,
I now is very simple but i can´t find the correct code, I want to add adsense to the final of my post but I add some pluggins and bars and I need to add it before one bar (sharethis pluggin), also I need it to add it in the content area,
I already try this code:
add_action(
'genesis_after_post_content'
,
'adsense_after_posts'
);
function
adsense_after_posts() {
if
(is_single() )
echo
'<div class="adsense-style">Adsense goes here</div>'
;
}
Thanks
http://April 17, 2013 at 2:54 am #35910Brad DaltonParticipantApril 17, 2013 at 11:20 am #35974ManuelMemberHi. Brad:
Here is the link
http://comodefinirabdominales.com/como-reducir-grasa-en-el-abdomen-sin-abandonar-la-rutina/
I want to add it before the share bar.
Thanks!
April 17, 2013 at 11:32 am #35976ManuelMemberAlso I need to add a Adsense banner before the shareThis pluggin but in the home page.
http://comodefinirabdominales.com/
Thanks!
April 17, 2013 at 5:32 pm #36025ManuelMembersorry, Also If you can help me with another issue, i need to add Adsense banner before the shareThis pluggin but in the home page, I get a little confused when I try to add the adsense.
Here is the link of my website:
http://comodefinirabdominales.com/
Thanks
Best Rewards!!
April 17, 2013 at 6:08 pm #36028Brad DaltonParticipantApril 18, 2013 at 2:17 am #36094ManuelMemberThanks Brad it work great.
I don't want to bother, but i get a little frustrated, I tried this code, it works, but if the post have photos or another element like a video it will avoid those elemnts, and the banner will be in another part
<code>
add_filter( 'the_content', 'wpsites_adsense_middle_content' );
function wpsites_adsense_middle_content( $content ) {
if( !is_single() )
return $content;$paragraphAfter = count ( $content ); //Enter paragraph number
$content = explode ( "</p>", $content );
$new_content = '';
for ( $i = 0; $i <= count ( $content ); $i ++ ) {
if ( $i == $paragraphAfter ) {
$new_content .= '<div style="width: 300px; height: 250px; padding: -5px -5px 0px 0; margin-right: 0;align=Top;display:inline-table;border:none;position:relative;float:left">';
$new_content .= '<script type="text/javascript">Script Adsense</script>';
$new_content .= '<center><strong>Enlace Patrocinado</strong></center></div>';
}
$new_content .= $content[$i] . "</p>";
}
return $new_content;
}</code>
Also i now that always in the content I have the <p></p> tag element, the last <p> is the ShareThis pluggin, I want to add it before the last <p> tag,I know i can count the elements of a class, but I cant implemented, What could be the best for to count the elements tags in a class, or is a function of theme than give me that info?
http://comodefinirabdominales.com/como-reducir-grasa-en-el-abdomen-sin-abandonar-la-rutina/
April 18, 2013 at 2:30 am #36099Brad DaltonParticipantThats my code also. Where did you get it?
You can't use that code for what you want because its developed to display the Adense after a specific amount of paragraphs which will be different on different posts.
You'll find Adsense converts better when its above the fold and typically before the content which is where you might want to display your Adsense.
I see you already add an image after posts so you have to change the hook or add a thrid parameter for the priority.
What code are you using for displaying the image after single posts?
April 18, 2013 at 1:17 pm #36203ManuelMemberI get it here , in the forum, you posted this code in another thread,I read past posts to try to solve this problem,, I use this code:
<code>
add_filter( 'the_content', 'wpsites_adsense_middle_content' );
function wpsites_adsense_middle_content( $content ) {
if( !is_single() )
return $content;$paragraphAfter = 0; //Enter paragraph number
$content = explode ( "</p>", $content );
$new_content = '';
for ( $i = 0; $i < count ( $content ); $i ++ ) {
if ( $i == $paragraphAfter ) {
$new_content .= '<div style="width: 300px; height: 250px; padding: -5px -5px 0px 0; margin-right: 0;align=Top;display:inline-table;border:none;position:relative;float:left">';
$new_content .= 'Adsense Code'
$new_content .= '<center><strong>Enlace Patrocinado</strong></center></div>';
}
$new_content .= $content[$i] . "</p>";
}
return $new_content;
}</code>
I aslo tied usging wp insert, but I cant get the position exactly where i want it, I want to Add a 300x250 banner between the image and the sharethis Bar, that the reason i want to add it always before the last<p> tag.
Thanks !!
April 18, 2013 at 7:17 pm #36255Brad DaltonParticipantO.k I Understand where you want it displayed but don't know which hook you are currently using for the after post image.
I think you should try and add another widget area before the image which looks like its using the same hook.
Which hook is it using Manual?
Or you could use another hook or add a priority to another function using the same hook or use 2 text widgets in the same widget area.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.