How can I add the facebook like button inside my single.php in wordpress without any plugin

If this question is not appropriate for the site I am sorry. In my wordpress site I want to add facebook like button with dynamic permalink in the single.php file but without any plugin. In other words i want to add like button after the post when the single post is open via single.php file. Any kind of help or suggestion is appreciated. Thanks.

Related posts

Leave a Reply

3 comments

  1. In your single.php file inside the loop

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    ....
    <?php the_content(); ?>
    <iframe src="http://www.facebook.com/plugins/like.php?href=<?php the_permalink() ?>&amp;send=false&amp;layout=button_count&amp;width=85&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:85px; height:21px;" allowTransparency="true"></iframe>
    <?php endwhile; ?>
    <?php endif; ?>
    

    You can read this.

  2. You can add this below code into functions.php.

          function setFacebookLike($content) {
      global $post;
          if($post->post_type=="post") {
    
              $content.= '<iframe src="http://www.facebook.com/plugins/like.php?href='.get_permalink($post->ID).'&amp;send=false&amp;layout=button_count&amp;width=85&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:85px; height:21px;" allowTransparency="true"></iframe>';
          }
          return $content;
      }
      add_filter ('the_content', 'setFacebookLike');