[Resolved] Link Post Author’s Name to a Site: Question re. PHP

Home Forums Support Link Post Author’s Name to a Site: Question re. PHP

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1315983
    Linda

    Hi Support,

    I’ve been searching support for the answer to this and found this:

    Custom Author Name
    One more example is if you want to completely customize your author name and link:

    add_filter( 'generate_post_author_output', function( $output ) {    
        return '<a href="MY CUSTOM URL">My Name</a>';
    } );

    My question is: where does this go? It’s PHP, correct? So can I add it via Code Snippets plugin?

    Thanks,

    Linda

    #1316160
    Leo
    Staff
    Customer Support

    Hi there,

    Yes that’s PHP so one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1316990
    Linda

    Thanks, Leo. I recall that article link from another time you helped me out. I’ll use the Code Snippet for now.

    Stay safe,

    Linda

    #1317312
    Leo
    Staff
    Customer Support
    #1322631
    Linda

    Well,phooey, Leo. It didn’t work.

    Here’s what I’m trying to do: link guest bloggers’ names to their web sites instead of to ours, as now happens.

    Here’s what I did: created a new Code Snippet and pasted the PHP below into it. I made one slight modification in line 2 due to error message:
    `add_filter( โ€˜generate_post_author_outputโ€™, function( $output ) {
    return โ€˜My Nameโ€˜;
    } );`
    I deleted the space in My Name since it returned a syntax error with the space (error marked with a wiggly red line which disappeared when I removed space).

    Once saved, the name link still reverts to our site. Did my modification cause this? Or is the PHP I found not the right one? Or did I insert it incorrectly? Or…??

    A second question: the author name doesn’t appear on the edit blog page so I’m not sure how I would add the correct link anyway! Is there a totally different way to fix this issue?

    Hope this all makes sense, Leo.

    Linda

    #1322732
    Leo
    Staff
    Customer Support
    #1325497
    Linda

    Positive suggestion, Leo. I did try David’s plugin. From all I read about it, however, I don’t think it will do what I want. It seems to refer to the role of a user, i.e., admin, author, editor…

    What I’m trying to do is change link from its default:
    https://mygoforthegreen.com/author/author-name/

    to something that will take a viewer to the author’s website: https://authorwebsite.com

    I don’t think I can replace “author-name” with the author’s website URL in an author slug. Or can I?

    None of the research I’ve been doing seems to give me a way to do this which is why I keep bugging you!

    Do you have anything else I can try? I’m not sure how else to handle links to guest bloggers’ sites. There has to be a way and I’m just not getting it.

    Thanks,

    Linda

    PS If there’s a way to stop author name from being automatically generated on the guest blogs, I could just type it in on the edit post page and add a hyperlink in the usual way.

    #1325713
    Tom
    Lead Developer
    Lead Developer

    Hi Linda,

    How many guest authors do you typically have? Are there still authors (like yourself) where you want to keep the current URL structure?

    Let me know ๐Ÿ™‚

    #1326516
    Linda

    Hi Tom,

    Trust you and your family are coping well with the “situation” we’re all in!

    90% of posts are currently written by my business partner or myself.

    That said, I’m pretty sure the current 10% guest author number will increase over time.

    Re. current author structure a question: not quite sure why current author name default is what it is, i.e., links author to our home page. Anyone who reads the blog is already on our site. Does it make sense to remove current author structure and just add author manually each time with its preferred URL link, as I mentioned earlier?

    Or am I missing something here that requires default structure to be maintained?

    Hope this makes sense!

    Linda

    #1326826
    Tom
    Lead Developer
    Lead Developer

    The current structure should link to the author archive for that specific author.

    You could disable the default link and manually add one to the content.

    Another option is to create a custom field in the “Users” area (using something like Advanced Custom Fields) where you can give each user a unique URL. Then we could filter the default output to use that URL if it exists.

    Let me know if you need help with the second option ๐Ÿ™‚

    #1327622
    Linda

    Thanks, Tom.

    The current structure should link to the author archive for that specific author.

    Hmm. Both Peter’s (partner) and my author names redirect me to our homepage and not to either author archive. Is this anything to worry about? Regardless …

    … to avoid taking up any more of your time, I think the simplest approach for now would be to disable the default link … as long as it won’t adversely affect SEO.

    Then, I would add author names only to guest posts and add links to their sites at the end of their articles.

    If this is valid technically and SEO-wise, could you please explain how to do this (or link me to an explanation). I did find this for OceanWP theme. Would it be the same for yours?

    Go to Customize > Blog > Blog Entry โ€“ find Meta option and click on the eye icon of the author elements.
    Repeat it for the single post page โ€“ Customize > Blog > Single Posts

    Thank you so much for helping me through this … and on your weekend, too! ๐Ÿ™‚

    Linda

    #1327913
    Tom
    Lead Developer
    Lead Developer

    Hi Linda,

    Yes, you’d do the same in GP. You’ll find a display author option in Customize > Layout > Blog for archives and single posts.

    We can also conditionally disable that with a PHP snippet if the author isn’t you or your partner. That way it would continue to display for both of you but wouldn’t display for the guest authors.

    #1329056
    Linda

    Excellent, Tom. Since it doesn’t affect technical or SEO issues, I’ll disable it for now and see how that goes. I’m glad to know we can conditionally disable the default with a PHP snippet later if disabling doesn’t work out for us.

    I also appreciate the confirmation “how to” you provided for GP and reminder to apply it in both archives and single posts. Will give this a try and let you know how it goes … or if I get stuck!

    Once again, thank you for your help and, especially, for getting back to me on a Sunday, family day!

    Stay safe,

    Linda

    #1329112
    Linda

    UPDATE: it worked in Customize … and it was easy to do, following your directions. I think all the research I’d done before coming to GP had me convinced fixing this was a hugely technical issue so I managed to totally confuse myself. Thanks for straightening me out! ๐Ÿ™‚

    Linda

    #1329166
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad it’s all working as needed. Thanks for letting me know ๐Ÿ™‚

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.