Community Forums › Forums › Archived Forums › Design Tips and Tricks › Customizing the Author Box Title is generating some weird results
- This topic has 8 replies, 2 voices, and was last updated 8 years, 7 months ago by Ronald.
-
AuthorPosts
-
September 20, 2015 at 3:49 pm #166169RonaldMember
So I wanted the Author Box Title to link to the author's archive page when on a single post, but not when the Author Box is used on the Archive Page.
I added the following code using the snippets here: http://my.studiopress.com/snippets/author-box/#modify-title
and the WordPress codex here: https://codex.wordpress.org/Function_Reference/the_author_posts_link//* Customize the author box title add_filter( 'genesis_author_box_title', 'custom_author_box_title' ); function custom_author_box_title() { if ( is_single() ) { return '<strong>About '.the_author_posts_link().'</strong>'; } else { return '<strong>About '.the_author().'</strong>'; } }
And these are the results I am getting using that code.
On the single post
On the Archive Page:
Both seem to place the author information separated above the actual Author Box. the_author_posts_link() does not display anything in the actual Author Box, but the_author() shows in both places.
I have no idea what could be causing this, Any ideas?
September 20, 2015 at 6:19 pm #166172Victor FontModeratorBoth the_author_posts_link() and the_author() functions must be used in the loop.They won't work anywhere else. What you want to use is: $author_link = get_author_posts_url( get_the_author_meta( 'ID' ) ); and $author = get_the_author();.
Here is your function rewritten:
//* Customize the author box title add_filter( 'genesis_author_box_title', 'custom_author_box_title' ); function custom_author_box_title() { if ( is_single('post') ) { $author_link = get_author_posts_url( get_the_author_meta( 'ID' ) ); return '<strong>About ' . $author_link . '</strong>'; } else { $author = get_the_author(); return '<strong>About ' . $author . '</strong>'; } }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?September 21, 2015 at 8:59 am #166214Victor FontModeratorThere's an error in the code I gave you above. I hadn't tested it in my local dev site before I posted and it bothered me a little because I didn't know if it would work or not. It doesn't work. I refactored it this morning and here is the version that will give you what you want. Sorry about the confusion.
//* Customize the author box title add_filter( 'genesis_author_box_title', 'vmf_custom_author_box_title' ); function vmf_custom_author_box_title() { if ( is_single() ) { $author = get_the_author(); $author_link = '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '">' . $author . '</a>'; return '<strong>About ' . $author_link . '</strong>'; } else { $author = get_the_author(); return '<strong>About ' . $author . '</strong>'; } }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?September 21, 2015 at 10:53 am #166222Victor FontModeratorThere's one concern I'd like to add about your approach. WordPress uses the user_nicename field as the URL for author archive pages. The user_nicename holds the same value as the user_login. There's no way to change this in the admin area. By using author archive pages, you are exposing user login ids to the world. There's no easy way to fix this. However, here's an article that explains how to change the user_nicename with PHPMyAdmin: http://premium.wpmudev.org/blog/change-admin-username/.
As an FYI, I would not use this code on any of my sites because of this security concern.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?September 21, 2015 at 7:58 pm #166281RonaldMemberOh wow thank you Victor, I did not even know about the security issue.
Thank you for all of your input, and if thats the case, I might have to re-consider not using the Author Archive Pages.
September 21, 2015 at 8:02 pm #166283RonaldMemberQuick question. If I did change the user_nicename in phpmyadmin, would that solve the security issue? Because, that would be an easy fix and I would still get the functionality I want.
If that doesn't actually fix the security issue, then I will probably just get rid of the author box. This is going to be a multi-author blog so it would be easier to use the genesis author box, then to hand-code a single "about the author" block that I have done in most of my other sites.
September 21, 2015 at 8:10 pm #166286RonaldMemberBtw, thank you for the code-snippet! it works perfectly...just got to figure out if I am actually going to use it now!
September 21, 2015 at 10:03 pm #166292Victor FontModeratorRonald, changing user_nicename would change the security issue. Keep in mind that user_nicename is used as a slug. It cannot contain spaces. You'll just have to make the change for every author.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?September 21, 2015 at 10:13 pm #166293RonaldMemberAh wonderful, well there is only going to be about 4-5 authors so this is a great work-around. Thank you again for the code-snippet and your security advice!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.