Site logo

[Support request] How to add Q&A area on Author page

Home Forums Support [Support request] How to add Q&A area on Author page

Home Forums Support How to add Q&A area on Author page

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #2525913
    Jeffrey

    Hey,

    I want to add question and answer area on my Authors page. How can I achieve it?
    You can take as an example this page – https://www.epicgardening.com/author/kelliklein/

    So, I want rich text area, which is bigger compared to a default Author bio area.

    #2526172
    David
    Staff
    Customer Support

    Hi there,

    you would need to use a plugin like ACF to add a Rich Text field to the User Profile page.
    Once thats in place we can assist with getting the user meta content and displaying it on your frontend.

    #2538902
    Jeffrey

    Hi David,

    I have created Rich Snippet ACF in Author.
    It’s represented in the Author edit page (admin panel).

    How can I represent it in Author archives?

    #2538966
    David
    Staff
    Customer Support

    Use a PHP Snippet to create yourself a shortcode to get that rich text:

    add_shortcode('author_qa', function(){
        $author_id = get_the_author_meta('ID');
        $author_qa = get_field('user_field_name', 'user_'. $author_id );
        $html = '<div class="author-qa">' . $author_qa . '<div>';
        
        return $html;
    });

    In the snippet, change: user_field_name to the name of your field.

    To display this, you can:

    1. Create a new Block Element:

    https://docs.generatepress.com/article/block-element-hook/

    2. Set the Hook to where you want it displayed eg. after_archive_description

    3. Add your [author_qa] Shortcode to the editor.

    4. Set the Display Rules > Location to: Author Archives

    5. Publish the element

    #2538999
    Jeffrey

    Where/How should I do the first part? (PHP Snippet & shortcode creation)

    #2539181
    Fernando
    Customer Support

    Hi Jeffrey,

    Here’s an article you may refer to regarding this: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2539731
    Jeffrey

    Update: It was HTML snippet, I changed it to PHP Snippet but nothing is shown.

    Old:
    When I try

    add_shortcode('author_faq', function(){
        $author_id = get_the_author_meta('ID');
        $author_qa = get_field('author_faq', 'user_'. $author_id );
        $html = '<div class="author-faq">' . $author_faq . '<div>';
        
        return $html;
    });

    It shows like this
    error

    What could be wrong?

    #2539778
    David
    Staff
    Customer Support

    1. This is the PHP Snippet:

    add_shortcode('author_qa', function(){
        $author_id = get_the_author_meta('ID');
        $author_qa = get_field('user_field_name', 'user_'. $author_id );
        $html = '<div class="author-qa">' . $author_qa . '<div>';
        
        return $html;
    });

    You add this to whatever PHP Snippet plugin you’re using.
    It will create a shortcode called: [author_qa]

    2. In your element, add the [author_qa] shortcode.

    #2539796
    Jeffrey

    This is the code I create in Code Snippets plugin.

    add_shortcode('author_qa', function(){
        $author_id = get_the_author_meta('ID');
        $author_qa = get_field('author_faq', 'user_'. $author_id );
        $html = '<div class="author-qa">' . $author_qa . '<div>';
        
        return $html;
    });

    Name of the new field is “author_faq”.

    It creates shortcode [wpcode id=”80391″]

    I insert this shortcode in Block elements, but it does not show up anything.

    What additional information can I provide to troubleshoot?

    #2540156
    David
    Staff
    Customer Support

    Can you share a link to where it should be displayed ?

    #2540159
    Jeffrey

    Under the description (above list of articles)

    https://www.traxplorio.com/author/niko-kashia/

    #2540233
    David
    Staff
    Customer Support

    Hold up….

    It creates shortcode [wpcode id=”80391″]

    I assume thats the plugin you’re using doing that ?

    As the snippet i gave you IS creating the shortcode [author_qa]

    So can you add [author_qa] to your element ?

    #2540299
    Jeffrey

    I tried that as well.

    You can check, it’s just text now.

    #2540301
    Jeffrey

    Oh, I made insertion logic different in Code Snippet and it worked.

    Thank you so much!

    #2540943
    David
    Staff
    Customer Support

    Glad to hear that

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