WordPress.org

Ready to get started?Download WordPress

Forums

How To Add Signature To Posts Without A Plugin? (41 posts)

  1. Shan
    Member
    Posted 2 years ago #

    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?

  2. It's a matter of when the filter gets queued and applied. Try modifying the add_filter() like so:

    add_filter('the_content','add_signature', 1 );

    I usually make my filters run later with ,11 so this may not work... If it does work it'll get applied earlier than the default priority.

  3. Shan
    Member
    Posted 2 years ago #

    OK, that worked. Thank you so much! But I can't get it centered. I added this to the css but nothing happened:

    div.signature img {
    padding: 5px;
    float: center;
    }

    Also, now my related posts are above my social icons. I have no clue how that happened. Any idea how to fix it?

  4. *Jan senses Esmi saying "Use the Firebug, Luke."*

    I always struggle with the CSS portion but this seems to do it.

    div.signature {
            text-align: center;
            padding: 5px;
    }

    I don't really know why, but it works. ;)

    Also, you want to save yourself grief and not hard code URLs like that. Try this modification to the function.

    add_filter( 'the_content' , 'add_signature' , 1 );
    function 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;
    }

    By using get_stylesheet_directory_uri() you can have the function figure out and produce the URI for the theme directory.

    Also, now my related posts are above my social icons. I have no clue how that happened. Any idea how to fix it?

    That's an odd one. Can you share the link?

    Edit: Forgot the padding.

  5. Shan
    Member
    Posted 2 years ago #

    Thanks I'll try the last bit and see what happens. :)

    And I did use Firebug -- can't live without it -- but none of the normal rules worked. I thought of text-align, but since it's an image, I didn't use it. LOL

    Here is a post: http://lastshredsofsanity.com/top-10-last-minute-valentines-gifts-not-to-buy-for-your-woman-unless-you-want-to-get-kicked-in-the-nuts/

    It's weird. I'm using LinkWithin for related posts and Sociable 2 for social icons (which just updated 15 minutes ago and is all kinds of FUBARED on settings)

  6. Shan
    Member
    Posted 2 years ago #

    Don't I need to add the image URL for the CSS now?

    Like this:

    div.signature {
            background: url('http:/yoursite.com/wp-content/themes/yourtheme/images/signature.png');
            text-align: center;
    }

    Never mind, that last bit did not work. :(

  7. It's weird. I'm using LinkWithin for related posts and Sociable 2 for social icons (which just updated 15 minutes ago and is all kinds of FUBARED on settings)

    Disable your add_filter() just to rule out any changes that you made. If it's still doing odd things, then it's the plugin.

    If it goes back to normal... it's something you've done. ;)

    Don't I need to add the image URL for the CSS now?

    If you want to use the image as a CSS background, then yes. But your function adds a img src= tag, so the png file is already there. Adding the additional background image isn't necessary.

  8. Shan
    Member
    Posted 2 years ago #

    Well it's either a a quote issue or my theme but the image won't show with the changed php you gave me.

    Parse error: syntax error, unexpected T_STRING in /home/XXX/public_html/wp-content/themes/shan-wp-ellie_basic/functions.php on line 2194

  9. Sorry, it's worse than that, there is a typo somewhere in that functions.php file!

    Can you undo the changes? Right now your WordPress blog is tossing errors.

    Also I apologize: I should always start with "Please make a backup copy before you edit that file".

  10. Shan
    Member
    Posted 2 years ago #

    Uggh. Back to original functions.php file now.

    Where is the typo? I suck at php code, if you haven't already guessed. LOL

    EDIT: still getting parse error even with original functions file added back. OY.

  11. It's still tossing errors for me. Do you have a backup?

    Or if you don't have a backup, can you use an original copy from where you got that theme?

  12. Shan
    Member
    Posted 2 years ago #

    I did add the original php code back to the functions file both via the theme editor and FTP. I don't get it. It's like it won't take.

  13. Hrm.

    Try this: Via your FTP client, rename the directory shan-wp-ellie_basic to shan-wp-ellie_basic-old.

    Now in that renamed dictory, rename shan-wp-ellie_basic-old/style.css to shan-wp-ellie_basic-old/style.css-old.

    What I want is for that messed up theme to stop being used. By renaming the directory and the style.css both, then WordPress should stop seeing that as a theme.

    Once you've done that, upload a backup copy of the entire shan-wp-ellie_basic folder there. This way you'll have two directories, one -old and the backup copy.

    See if that works.

  14. Shan
    Member
    Posted 2 years ago #

    This is the error I'm getting:

    Parse error: syntax error, unexpected '}' in /home/XXX/public_html/wp-content/themes/shan-wp-ellie_basic/functions.php on line 1
  15. Yep, that's the same error I'm seeing too.

  16. Shan
    Member
    Posted 2 years ago #

    Ok, I named the original -old and uploaded a clean theme. Is it Ok to add the style sheet?

  17. *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?

  18. Shan
    Member
    Posted 2 years ago #

    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

  19. 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! :D

  20. Shan
    Member
    Posted 2 years ago #

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

  21. 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.

  22. Shan
    Member
    Posted 2 years ago #

    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.

  23. Shan
    Member
    Posted 2 years ago #

    I still can't get that second code you posted to work. :(

  24. 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... :D )

    <?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.

  25. Shan
    Member
    Posted 2 years ago #

    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. :D

    And yes, very cool name.

  26. Shan
    Member
    Posted 2 years ago #

    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.

  27. 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.

  28. Shan
    Member
    Posted 2 years ago #

    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)

  29. Shan
    Member
    Posted 2 years ago #

    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
  30. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic