[Resolved] Add element to posts by specific author

Home Forums Support Add element to posts by specific author

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1286517
    Carson

    Hi there,

    is there any way to display an element only on posts by specific authors?

    Alternatively, can I add CSS to pages by specific authors in any other way?

    Thanks!

    #1287561
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You can:

    1. Add a new Element, but leave the Display Rules empty.
    2. Take note of the Element ID (in the URL while editing the Element).
    3. Add a filter:

    add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
        $author_id = get_post_field( 'post_author', get_the_ID() );
    
        if ( 1234 === $element_id && '123' == $author_id ) {
            $display = true; // If Element ID is 1234 and author ID is 123, display the Element.
        }
    
        if ( 5678 === $element_id && '456' == $author_id ) {
            $display = true; // If Element ID is 5678 and author ID is 456, display the Element.
        }
    
        return $display;
    } );
    #1288779
    Carson

    Thank you!!!

    #1289254
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.