Support » Fixing WordPress » How To Add Signature To Posts Without A Plugin?

  • Shan

    (@shan-last-shreds-of-sanity)


    I found a hack that sort of worked:

    I added this to my functions.php file:

    add_filter('the_content','add_signature');
    function add_signature($text) {
     global $post;
     if($post->post_type == 'post') $text .= '<div class="signature"> <img src="http:/yoursite.com/wp-content/themes/yourtheme/images/signature.png" alt="signature" /> </div>';
     return $text;
    }

    But instead of my signature being directly under the content, it was below both my linkwithin & sociable plugin stuff and above the tags/category meta info. How do I code it so that it goes directly at the end of my posts and above all the other stuff?

Viewing 15 replies - 16 through 30 (of 40 total)
  • Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    *WHEW*

    That looks much better! You are using the theme in wp-content/wp-ellie, do you know what you changed when you created shan-wp-ellie_basic?

    Can you recreate the old theme as it was before this functions.php editing?

    Shan

    (@shan-last-shreds-of-sanity)


    Yeah, I think I can. Just copy and paste the style sheets & the header. php from the old one. I already added back all the images.

    Guess hard coding my signature is a bad idea, eh? LOL

    Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    Guess hard coding my signature is a bad idea, eh? LOL

    Nah, it’s just all about the safety nets. I used to start all my replies and advice with something like this:

    Make sure you backup your files and database before you start modifying your installation.

    http://codex.wordpress.org/WordPress_Backups
    http://codex.wordpress.org/Backing_Up_Your_Database
    http://codex.wordpress.org/Restoring_Your_Database_From_Backup

    Good backups and knowing how to restore them are the best safety net you can have. Which I think you fully get 100%. 🙂

    I think if you can put it back the way it was before this, then call it a night.

    Don’t be discouraged, if you still want to work on your signature then as long as you make a copy of the file you are editing you really can’t cause too much harm. And recovering from something like this really is the best way to pick this all up.

    And on that cheerful note, I say good night! 😀

    Shan

    (@shan-last-shreds-of-sanity)


    Before you go, what was the typo in the code you gave me? Was it ‘uri’ instead of ‘url’?

    Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    I used that code exactly as it’s written on my Crash Test Dummy WordPress install™. I use it to make sure I don’t give out bad code. o_O

    In fact, just to make sure, I copied it again exactly as above.

    I still don’t get any errors, the code is good. You can see the results at http://dixie.dembowski.net/wordpress/microsoft-touch-mouse/. I don’t have a signature.jpg so I used a copy of my Gravatar.

    It’s even centered at the bottom.

    Shan

    (@shan-last-shreds-of-sanity)


    I dunno, then.

    Did I mention that technology hates me? We have a love-hate relationship. I love to try and make it do things and it hates it so it breaks on me. EVERY. TIME.

    Shan

    (@shan-last-shreds-of-sanity)


    I still can’t get that second code you posted to work. 🙁

    Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    For now, try it as a plugin instead. If bad things happen just delete the plugin file.

    If it works, you can later add it to your theme’s functions.php file (and of course, making complete backups of everything before you do… 😀 )

    <?php
    /*
    Plugin Name: Shan's Excellent Signature Plugin
    */
    add_filter( 'the_content' , 'shan_add_signature' , 1 );
    function shan_add_signature($text) {
       global $post;
       if($post->post_type == 'post') $text .= '<div class="signature"> <img src="' . get_stylesheet_directory_uri() . '/images/signature.jpg" alt="signature" /> </div>';
       return $text;
    }

    Normally I would make a pastebin.com link for that code, but at the moment I am somewhere that blocks access to that site.

    Copy this text into a new text file called shan-signature.php and using FTP upload that file to your wp-content/plugins directory.

    Visit your plugin page and look for “Shan’s Excellent Signature Plugin” (cool name, no?) and activate that.

    If it works, you’ll see it. If Bad Things™ happen again, use FTP and delete the new plugin shan-signature.php and you’ll be back to normal.

    Shan

    (@shan-last-shreds-of-sanity)


    You made me a plugin? Awww. Thanks. 🙂

    I’ll try it out and let you know how it works. By the way, I love how you trademarked “bad things” in your post. 😀

    And yes, very cool name.

    Shan

    (@shan-last-shreds-of-sanity)


    It didn’t work. I added it via FTP but it won’t even show on my plugins page. Should I zip it first?

    And no signature shows up on posts. I had to change the image extension to .PNG in the code because mine has a transparent background but I didn’t think that would mess anything up. I even added the image to my theme images golder as signature.PNG

    I’m stumped, as usual.

    Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    No, that should have worked if the file was named shan-signature.php and the code was copied in, and that file was copied to wp-content/plugins

    I just tried it myself on my Crash Test Dummy. Centered image at the end of the post.

    Can you check the permissions on that new file on your server? I’m not too familiar with FTP (industry thing, I never use FTP myself) but the file permissions should be something like rw-r--r-- for that new file.

    Shan

    (@shan-last-shreds-of-sanity)


    I didn’t name it that. I named it Shan’s Excellent Signature Plugin. Let me fix that and see what happens.

    (How did I miss the naming the file correctly part? OY)

    Shan

    (@shan-last-shreds-of-sanity)


    Well the plugin is there now after the deletion of the old one and renaming/re-upload.

    BUT, I got this error and my site is all FUBARED:

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/shan/public_html/wp-content/plugins/shan-signature.php:2) in /home/shan/public_html/wp-content/plugins/easy-contact/econtact.php on line 112
    Moderator Jan Dembowski

    (@jdembowski)


    Brute Squad and Volunteer Moderator


    Nah, that’s easy to fix. 🙂 Just some blank space that PHP doesn’t like.

    Delete the plugin you just FTP’ed and save this one

    http://pastebin.com/download.php?i=pPxEf0N2

    That link will save as shan-signature.php.txt. Delete the .txt from the end (change the extension to just .php) and use FTP to copy it to wp-content/plugins.

    That should work.

    Shan

    (@shan-last-shreds-of-sanity)


    Well the plugin loaded fine with no errors.

    But I have no siggy, just this:

    http://img10.imageshack.us/img10/9577/ssigpluginfail.png

Viewing 15 replies - 16 through 30 (of 40 total)
  • The topic ‘How To Add Signature To Posts Without A Plugin?’ is closed to new replies.