Support » Fixing WordPress » How to hard code social media icons to end of posts/pages?

  • Shan


    I’ve been searching for tutorials for this, but can’t find any. I’m trying to reduce my plugins and since I currently need two separate plugins to have the social media icons the way I want them, I thought hard coding the ones at the end of posts/pages would be easiest to accomplish.

    Anyone know of a tutorial for this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You probably don’t need a plugin. Create a filter on the_content and append the proper HTML in it.

    Your filter could be as simple as this (UNTESTED):

    function my_function($content){
       $my_text = "<p>Here is more content.</p>";
       return $content . $my_text;
    add_filter('the_content', 'my_function');


    Thank you.

    What file would I add this to and how do I make sure the icons appear at the end of the post after my signature? Could I use the code just as you have posted it after adding my HTML or are there more changes I would need to make?

    The code goes in your functions.php, but be careful! If you have any errors in functions.php it will make your site unusable and you will need to use ftp (or a File Manager from your hosting service) to correct it.

    Whether it appears before or after your signature depends entirely on your theme and how the signature is added.

    If your signature is added by a plugin or a widget, can you put the HTML for the social media icons with it?



    My siganture is hard coded in the functions php file because the plugins kept screwing up on me.

    The code is below:

    add_filter( 'the_content', 'add_signature', 1 ); 
    function add_signature($text) { 
    	global $post; 
    	if($post->post_type == 'post') 
    		$text .= '<div class="signature"><center><img src="" alt="signature" /></center></div>';
    	return $text; 

    My theme is WP-Ellie. You can see my site here:

    Then the icons code could just be added to that function, but it looks like you would need to test for both ‘post’ and ‘page’ page_type before adding it.



    Yeah, what you said is all Greek to me. LOL I am not a good coder at all.

    I can’t tell you exactly how to insert your code because it may have things in it that would change the way it needs to be inserted. You can try using the code below, but remember that if there is an error, you will need to use ftp to correct it.

    Add this under the global $post; line:

    $extra_text <<<EOTEXT
    your extra code replaces this line

    Be sure that the ‘EOTEXT;’ line starts at the left margin. It won’t work otherwise.

    Then, insert this code as explained below:

    if ($post->$post_type == 'post' || $post->post_type == 'page') $text .= $extra_text;

    If you want your extra text before your signature, insert that line before the existing if($post->post_type == 'post') line.

    If you want the extra text after the sig, put that line just before the ‘return $text;’ line.

    If you would like to be sure that this will not cause errors, put the code for the extra text in a pastebin and post a link to it here and I will check it for you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to hard code social media icons to end of posts/pages?’ is closed to new replies.