Site logo

Archived topic

Load Author Box (block element) on posts and pages based on author ID

8 replies · Started by Incal on June 20, 2022

Viewing posts 1–9 of 9

Hi,

I found this code in another support topic:

add_filter( 'generate_block_element_display', function( $display, $element_id ) {
    $author_id = get_post_field( 'post_author', get_the_ID() );

    if ( 553 === $element_id && '2' == $author_id ) {
        $display = true;
    } else if ( 553 === $element_id && '2' != $author_id ){ 
	$display = false; 
    }

    return $display;
}, 15, 2 );

It works for posts but the element doesn't load on pages. Could you please let me know what I can tweak to load my author box on posts and pages for the selected author?

Many thanks,
Kevin

Hi Fernando,

Thank you for the quick reply.

On second look, it seems that the element is loading but the author box doesn't appear on pages. It works fine on posts though.

Please see examples in the private section.

Many thanks,
Kevin

Also, one thing I noticed is that the block appears also in archive pages (e.g. blog). Would it be possible for it to appear only on single posts and pages?

Thank you,
Kevin

Hi there,

quick question - are you wanting a different author box each author ?

Hi David,

Yes, because pretty much each author has different social media profiles available. E.g. one will have only Instagram, but another one will only have their website..etc.

Thanks,
Kevin

Hi David,

Thank you so much! I didn't know that icons were automatically hidden if there was no link available for the author.

Best,
Kevin

You're welcome!

This archived topic is closed to new replies.