Problem with adding co-authors plus to post meta

Hi there. Since the latest update the code I was using to show multiple authors with links to their pages underneath the post meta isn’t working anymore. Using the Co authors plus plugin. I originally had this code replacing authors in my function child file:

if ( function_exists( 'coauthors_posts_links' ) ) {
    coauthors_posts_links();
} else {
    the_author_posts_link();
}

But now it shows a undefined variable underneath the author:

Notice: Undefined variable: author in /var/sites/v/---/public_html/wp-content/themes/x-child/functions.php on line 232

(not have removed the website url in that error message and replaced with the —).

Have tried some tweaks but no luck so far.

Many thanks for the help.

Hey,

if you could post some logins details in a secure note and we`d be happy to take a look.

P.S: You can search by “secure note” on this article if you don`t know about this: https://theme.co/apex/forum/t/themeco-support-overview/288

Great thanks, I think I’ve done the secure note correctly with the login details.

Hi There,

Please try using this function instead: get_the_author_posts_link()
See this: https://developer.wordpress.org/reference/functions/get_the_author_posts_link/
https://wp-a2z.org/oik_api/the_author_posts_link/

Let us know how this goes.

Thanks, no joy I’m afraid. We’re still getting the notice.

Hi There,

I am not sure how it is added before but if that is the complete code you are using, it should be added on the content template for the post. Something like this:

if ( function_exists( 'coauthors_posts_links' ) ) {
   coauthors_posts_links();
} else {
   echo get_the_author_posts_link();

}

Since it is also just a notice, you can just disable the WP_DEBUG to get rid of these.

You can do this by opening wp-config.php and updating

define( ‘WP_DEBUG’ , true );

to

define( ‘WP_DEBUG’ , false );

Hope this helps.

I didn’t include ‘echo’ before, but with it we are still getting the notice. Have disabled WP_DEBUG to remove the notice for now,that should do it.

Thanks very much :slight_smile:

Glad we could help.

Cheers!

Hi. Following this thread.
I recently updated to Pro from X and in doing so lost all the code I had that allowed my Co-Authors Plus plugin to display two authors in my Post’s Meta.

Can you provide me with the code necesary to make this happen in Pro?

Following the instructions in this thread I copied this code to the functions.php file present in my Pro-Child theme but noting is happening.

function get_the_author_posts_link() {
    global $authordata;
    if ( ! is_object( $authordata ) ) {
        return;
    }
 
    $link = sprintf( '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
        esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
        /* translators: %s: author's display name */
        esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
        get_the_author()
    );
 
    /**
     * Filters the link to the author page of the author of the current post.
     *
     * @since 2.9.0
     *
     * @param string $link HTML link.
     */
    return apply_filters( 'the_author_posts_link', $link );
}

Hi,

That is wordpress default function

https://developer.wordpress.org/reference/functions/get_the_author_posts_link/

You can try this code instead.

// Entry Meta
// =============================================================================

if ( ! function_exists( 'x_integrity_entry_meta' ) ) :
  function x_integrity_entry_meta() {

    //
    // Author.
    //

if ( function_exists( 'coauthors_posts_links' ) ) {
    coauthors_posts_links();
} else {
    echo get_the_author_posts_link();
}

    //
    // Date.
    //

    $date = sprintf( '<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar" data-x-icon="&#xf073;"></i> %2$s</time></span>',
      esc_attr( get_the_date( 'c' ) ),
      esc_html( get_the_date() )
    );


    //
    // Categories.
    //

    if ( get_post_type() == 'x-portfolio' ) {
      if ( has_term( '', 'portfolio-category', NULL ) ) {
        $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
        $separator         = ', ';
        $categories_output = '';
        foreach ( $categories as $category ) {
          $categories_output .= '<a href="'
                              . get_term_link( $category->slug, 'portfolio-category' )
                              . '" title="'
                              . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                              . '"><i class="x-icon-bookmark" data-x-icon="&#xf02e;"></i> '
                              . $category->name
                              . '</a>'
                              . $separator;
        }

        $categories_list = sprintf( '<span>%s</span>',
          trim( $categories_output, $separator )
        );
      } else {
        $categories_list = '';
      }
    } else {
      $categories        = get_the_category();
      $separator         = ', ';
      $categories_output = '';
      foreach ( $categories as $category ) {
        $categories_output .= '<a href="'
                            . get_category_link( $category->term_id )
                            . '" title="'
                            . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                            . '"><i class="x-icon-bookmark" data-x-icon="&#xf02e;"></i> '
                            . $category->name
                            . '</a>'
                            . $separator;
      }

      $categories_list = sprintf( '<span>%s</span>',
        trim( $categories_output, $separator )
      );
    }


    //
    // Comments link.
    //

    if ( comments_open() ) {

      $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
      $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
      $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );

	  $text = ( 0 === $number ) ? 'Leave a Comment' : sprintf( _n( '%s Comment', '%s Comments', $number, '__x__' ), $number );

$comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon="&#xf086;"></i> %3$s</a></span>',
        esc_url( $link ),
        esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
        $text
      );

    } else {

      $comments = '';

    }


    //
    // Output.
    //

    if ( x_does_not_need_entry_meta() ) {
      return;
    } else {
      printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
        $author,
        $date,
        $categories_list,
        $comments
      );
    }

  }
endif;

Hope that helps.

I copy that into my child theme’s function’s php:
public_htm//wp-content/themes/pro-child/functions.php

and nothing happend. Is that where its supposed to be?

Hi There @TaverasJose

Did you activate your child theme before testing this changes? Make sure it’s activated under Appearance -> Themes section.

If not, provide us with the link to your site to check.

Thanks!

Oh my god!
I’m embarrased. Of course you are right
Thats working.
Thank you so much. Sorry for the oversight and thanks for your time.

Glad we could help.

Cheers!

Hi! thanks to your code I was able to display two authors on my blog post. But how do I get rid of it displaying the authors two times?

Here is the sample post: http://projectredstudios.com/2018/06/03/zoie-18/

Thanks!

Hello There,

Thanks for updating this thread. It seems that you have a custom code that inserts the author’s link below the post titles. Please remove your custom if you want to display the author link along with the other post meta.

If what you want is to display the author right below the titles and get rid of the other post meta, you may disable the post meta in X > Theme Options > Blog > Content.

Hope this helps.

Hi! thanks for the reply. But I want to keep the author preview with the pencil icon and the other metas beside it. I want to get rid of the one just below the title. :slight_smile:

Thank you!

I see. Regretfully, that would require further custom development which would be getting outside the scope of our support. What we have provided already serves for further customization. It is meant to be understood by a developer though so if the code given is hard to understand, you will need to hire a developer to continue the custom development.

Thank you for understanding.

Hi, I’m attempting to get this to work as well. Which template file would i add this code to?

Hi Greg,

Please follow Paul’s instruction above.

If you have a follow-up question, please write it on a new thread as this one is getting longer and hard to follow.

How To Post A Support Question

Thanks,