• Resolved wordpresscoder

    (@wordpresscoder)


    Hi!
    I would like to change “”Show contact information” in the bottom of every add to the link to author page. Is that possible? I would also like to change it to “Contact *author username*”

    I have already been able to link the authors name as a link but not this contact button.

    Best regards
    Wordpresscoder

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, you can do this by adding the code below in your theme functions.php file

    
    add_action( "init", "custom_button_init" );
    function custom_button_init() {
        remove_action('adverts_tpl_single_bottom', 'adverts_single_contact_information');
        add_action('adverts_tpl_single_bottom', 'custom_button_html');
    }
    function custom_button_html( $post_id ) {
        ?>
        <div class="adverts-single-actions">
            <a href="#your-link-here" class="adverts-button" data-id="<?php echo $post_id ?>">
                <?php esc_html_e("Contact Author", "adverts") ?>
            </a>
        </div>
        <?php
    }
    
    Thread Starter wordpresscoder

    (@wordpresscoder)

    Thank you @gwin
    But how do I make it link to the author profile? If the user post an add I would like it to link to that user.
    Is it possible?

    Plugin Author Greg Winiarski

    (@gwin)

    If you want to display a link to page with author posts you need to replace #your-link-here with get_author_post_url() function see https://codex.www.ads-software.com/Function_Reference/get_author_posts_url

    Thread Starter wordpresscoder

    (@wordpresscoder)

    @gwin thank you for your support. However I would like the button to link to the “user profile” who made the add. I am not good with PHP. I was able to make a link to the user profile but the button disappeared so I made something wrong.
    I am almost there!

    Plugin Author Greg Winiarski

    (@gwin)

    Can you paste the code you already have?

    Thread Starter wordpresscoder

    (@wordpresscoder)

    @gwin

    add_action( "init", "custom_button_init" );
    function custom_button_init() {
        remove_action('adverts_tpl_single_bottom', 'adverts_single_contact_information');
        add_action('adverts_tpl_single_bottom', 'custom_button_html');
    }
    function custom_button_html( $post_id ) {
        ?>
        <div class="adverts-single-actions">
            <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?>" class="adverts-button" data-id="<?php echo $post_id ?>">
                <?php esc_html_e("Contact Author", "adverts") ?>
            </a>
        </div>
        <?php
    }
    Plugin Author Greg Winiarski

    (@gwin)

    Most likely the HTML in custom_button_html should be

    
        <div class="adverts-single-actions">
            <a href="<?php echo get_author_posts_url( get_post( $post_id )->post_author ); ?>" class="adverts-button">
                <?php esc_html_e("Contact Author", "adverts") ?>
            </a>
        </div>
    
    Thread Starter wordpresscoder

    (@wordpresscoder)

    @gwin it works! Thanks a lot! Great ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Link “Show contact information” to author page’ is closed to new replies.