0

i wanted to execute a code after the Content of each blog post. I just want it to be on posts and not on pages. I could execute simple html by the method but could not put the following content. Please help me out with a code to execute the following code at the end of content.

    <div class="css">
<?php if ( should_display_link() ) : ?>
[subscribe-author-button]
<?php echo '<a class="btn" style="background-color:#1f1fff; border-radius:100px;" href="'.site_url('chat/').'?new-message&to='.get_the_author_meta( 'user_login' ).'">Chat</a>' ; ?>
<?php endif; ?>
[simple-author-box]
<?php if ($post->post_status == "publish")  { ?>
<h4>[post-views]</h4>
<?php   }  else {echo "<span></span>";} ?> 
<?php if ( should_display_link() ) : ?>
<a class="btn" href="https://adityaagarwal3.typeform.com/to/Lin6FB" data-mode="popup" style="background-color:#DB4437;color:white;border-radius:25px;" data-hide-headers=true data-hide-footer=true data-submit-close-delay="5" target="_blank">Report Content </a> <script> (function() { var qs,js,q,s,d=document, gi=d.getElementById, ce=d.createElement, gt=d.getElementsByTagName, id="typef_orm_share", b="https://embed.typeform.com/"; if(!gi.call(d,id)){ js=ce.call(d,"script"); js.id=id; js.src=b+"embed.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(js,q) } })() </script>
<?php endif; ?>

</div>
0

You can try my approach which is used to do your requirement:

function themename_your_content_after($content) {
    if( is_single() ):
    ob_start();
    ?>
     <div class="css">
    <?php if ( should_display_link() ) : ?>
    [subscribe-author-button]
    <?php echo '<a class="btn" style="background-color:#1f1fff; border-radius:100px;" href="'.site_url('chat/').'?new-message&to='.get_the_author_meta( 'user_login' ).'">Chat</a>' ; ?>
    <?php endif; ?>
    [simple-author-box]
    <?php if ($post->post_status == "publish")  { ?>
    <h4>[post-views]</h4>
    <?php   }  else {echo "<span></span>";} ?> 
    <?php if ( should_display_link() ) : ?>
    <a class="btn" href="https://adityaagarwal3.typeform.com/to/Lin6FB" data-mode="popup" style="background-color:#DB4437;color:white;border-radius:25px;" data-hide-headers=true data-hide-footer=true data-submit-close-delay="5" target="_blank">Report Content </a> <script> (function() { var qs,js,q,s,d=document, gi=d.getElementById, ce=d.createElement, gt=d.getElementsByTagName, id="typef_orm_share", b="https://embed.typeform.com/"; if(!gi.call(d,id)){ js=ce.call(d,"script"); js.id=id; js.src=b+"embed.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(js,q) } })() </script>
    <?php endif; ?>
    </div>
    <?php
    $code_content = ob_get_clean();
    $content .= $code_content;
    endif;
    return $content;
}
add_filter('the_content', 'themename_your_content_after');
  • Thanks. Will let you know in a few minutes, if it works – Aditya Agarwal Feb 28 at 5:10
  • It will output the code after every post content on the single post page. So if you have any “related posts” on that site, they will also get appended. – Krzysiek Dróżdż Feb 28 at 6:00
  • It worked well. The code is executed before the related posts and comments section at my site and that is as expected. Thanks – Aditya Agarwal Feb 28 at 9:45
  • Great @AdityaAgarwal. Good Luck! – Balas Feb 28 at 11:08

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.