Archived topic
Disabling linking to author's posts
33 replies · Started by Remez Sasson on May 25, 2015
I would like to disable the link in the post's author name, beneath the title of the post.
I want author's name to remain, but I don't want it to be a link. Currently the link leads to all the author's posts.
Thank you
Adding this function should do the trick: https://gist.github.com/generatepress/67fb28af5c8be3103290
Adding PHP: http://generatepress.com/knowledgebase/adding-php-functions/
I added the code in the link above, https://gist.github.com/generatepress/67fb28af5c8be3103290 to the functions.php file, but then my blog went blank, so I removed it.
Can you help please?
Thank you
Remez
I just tested it and it worked.
Did you add it to your child theme's functions.php?
I added the following script again, as per the link above, a few minutes ago, but the author's name beneath the title is still a link.
if ( ! function_exists( 'generate_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function generate_posted_on() {
if ( 'post' !== get_post_type() )
return;
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span> <span class="byline">%2$s</span>', 'generate' ),
sprintf( '%3$s',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
),
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="author-name" itemprop="name">%2$s</span></span>',
__( 'by','generate'),
esc_html( get_the_author() )
)
);
}
endif;
Try adding it using this plugin: https://wordpress.org/plugins/code-snippets/
Just a note for others, don't use the code pasted above - use the code I originally linked to.
I didn't want to add another plugin to the blog, so I tried again inserting the code you supplied to the child theme functions.php, but this time i did not upload it with trough ftp, but pasted into the functions.php through the editor in WordPress, and it worked, removing the link.
I don't understand why it didn't work by uploading it through ftp, but the important thing is that this issue is solved now.
Thank you for your help,
Remez Sasson
That's very odd - I can't think of a reason why FTP wouldn't work, it's actually more reliable than other methods.
Either way, glad it worked! :)
Hi Tom,
I pasted the above code to theme's function.php.
Yet, author link is click-able.
Am i doing anything wrong?
Also, how can i disable the link on the date.
Thank You.
Are you using a child theme? If so, is the filed name functions.php (with an s)?
This function will remove the link to the date and author: https://gist.github.com/generatepress/17e92621b6bf1140dafa
Just some feedback: I also wanted to remove the link to the author profile (so as to hide my username), but leave the author name there in post metadata. I used Tom's suggestion to create a plugin with Pluginception.
I made the plugin, pasting exactly the code Tom linked to at: https://gist.github.com/generatepress/67fb28af5c8be3103290.
It worked perfectly! Thanks!
Perfect! Glad it worked :)
It works for me on Pages, but not on Post-Pages. Is there an other Filter for it?
Authors don't show up on pages, only posts.
This is the only function/filter that applies to authors in the theme.
There is a Problem, these two filters do not work together:
if ( ! function_exists( 'generate_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function generate_posted_on() {
if ( 'post' !== get_post_type() )
return;
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span> <span class="byline">%2$s</span>', 'generate' ),
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
),
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="author-name" itemprop="name">%2$s</span></span>',
__( 'by','generate'),
esc_html( get_the_author() )
)
);
}
endif;
if ( ! function_exists( 'generate_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function generate_posted_on() {
if ( 'post' !== get_post_type() )
return;
printf( __( '<span class="byline">%1$s</span>', 'generate' ),
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
__( 'by','generate'),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generate' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
}
endif;