Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a child theme and try to get some code show up after the content on single post/pages

function app_bits() {
global $post;
$app_logo = get_post_meta($post->ID, 'AppLogo', TRUE);
$zund_id = get_post_meta($post->ID, 'AppURL', TRUE);
if ( is_single() || is_page() ) {
?>
<div class="hidemobile">
<div class="one_half">
<!--  ad code  -->
sample
</div>
<div class="one_half column-last">
<?php
if ($zund_id !='') {
?>
<div style="text-align: center;">custom code goes here
</div>
<?php } else { ?>
<div style="text-align: center;">custom code goes here
</div>
<?php } ?>
</div>
</div>
<?php
    }
}
add_filter( 'the_content', 'app_bits');

The issue is it replaces the content. Is there a after_the_content hook I can use so that the content I want goes after the content?

After reading what @toscho said that I came up with this ( I am not some one who uses PHP , which should become obvious after looking at the code below -_- ) if anyone esle is looking for the same , here is what I used

function app_bits($content) {
global $post;
$app_logo = get_post_meta($post->ID, 'AppLogo', TRUE);
$zund_id = get_post_meta($post->ID, 'AppURL', TRUE);
if ( !is_singular() ) 
{
return $content;
}
$custom_bits1='<div class="hidemobile">
<div class="one_half">
<!--  ad code  -->
sample here
</div>
<div class="one_half column-last">';
$custom_bits2='<div style="text-align: center;">custom code goes here
</div></div></div>';
$custom_bits3='<div style="text-align: center;">custom code goes here
</div></div></div>';
if ($zund_id !='') {
return $content . $custom_bits1. $custom_bits2;
} else {
return $content . $custom_bits1. $custom_bits3;
}
}
add_filter( 'the_content', 'app_bits');
share|improve this question
1  
you should not echo the content through the function, you should return it. Or if you want to use echo, take a look at output control functions in php –  Mridul Aggarwal Oct 19 '12 at 11:28
    
@MridulAggarwal In such cases where a comment fixes an issue, it should've been an answer instead and followed by a short example - go for rep points, man! –  kaiser Oct 19 '12 at 11:36
    
@kaiser I'll do that from next time, but this time toscho answered first, so i'll pass –  Mridul Aggarwal Oct 19 '12 at 11:52

1 Answer 1

up vote 2 down vote accepted

You get the $content as a parameter for your function, and you should not echo anything in that function. Return a string instead.

Example:

add_filter( 'the_content', 'app_bits');

function app_bits( $content )
{
    if ( ! is_singular() ) 
    {
        return $content;
    }

    $extra = '<div style="text-align: center;">custom code goes here</div>';

    return $content . $extra;
}

See How to return loop contents for an example showing how to return a rather complex string with markup.

share|improve this answer
    
thanks I will take a crack at it –  Saijo George Oct 19 '12 at 11:41
    
small hint for the conditional statemant, the is_preview is often forgotten, but usefull. –  bueltge Oct 19 '12 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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