Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[Resolved] Show a specific thing in single post when a specific author wrote that post

Home Forums Support [Resolved] Show a specific thing in single post when a specific author wrote that post

Home Forums Support Show a specific thing in single post when a specific author wrote that post

  • This topic has 6 replies, 2 voices, and was last updated 6 years ago by Tom.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #419314
    themedleb

    Hello,

    If we are two or more authors in the website, each with it’s own adsense code, we need our ads to be displayed on single posts, each specific ad should be displayed in the single post where a specific author posted/published it.

    ———————————–
    Example:
    user-id: 1111 | adsense code: aaaa
    user-id: 2222 | adsense code: bbbb
    user-id: 3333 | adsense code: cccc
    user-id: 4444 | adsense code: dddd

    if random post published by user-id: 1111, the adsense code: aaaa should appear
    if random post published by user-id: 2222, the adsense code: bbbb should appear
    if random post published by user-id: 3333, the adsense code: cccc should appear
    if random post published by user-id: 4444, the adsense code: dddd should appear
    and so on …
    ———————————–

    Is there a PHP code I can insert in single.php/content-single.php to show a specific thing (let’s say shortcode) to appear when a specific author wrote the post?

    Thank you.

    #420307
    Tom
    Lead Developer
    Lead Developer

    Hmm, something like that would take quite a bit of coding I think – a bit too much for the forum here.

    Your best bet would likely be a plugin – there must be one out there, as I would think it’s a pretty common problem.

    #420674
    themedleb

    Oh, I asked because I thought it’s going to be just like a code you used to give before, something like:

    is_single {

    if (author-id==8581){
    echo do_shortcode(‘[ad1]’);

    }elseif (author-id==8582){
    echo do_shortcode(‘[ad2]’);

    }elseif (author-id==8583){
    echo do_shortcode(‘[ad3]’);

    }else{
    echo do_shortcode(‘[ad4]’);
    }
    }

    Of course this has no sense since I have no clue on PHP, I’m just trying to guess from random thoughts lol. Anyway, thank you.

    #420950
    themedleb

    Unfortunately I looked in WordPress repo inside WordPress and from Google, there is no plugin offers this.

    I found the function is_author https://developer.wordpress.org/reference/functions/is_author/ but I don’t know how to use it, and don’t know if I can add it with is_single function to work as: if it’s a single post + written by author(‘4’) then show this shortcode.

    #421297
    Tom
    Lead Developer
    Lead Developer

    You could do something like this:

    if ( '123' == get_the_author_meta( 'ID' ) ) {
        echo do_shortcode( '[whatever]' );
    }
    #421700
    themedleb

    Wow It works, I was so worried about this, thank you Tom for your kind help and precious time.

    #421757
    Tom
    Lead Developer
    Lead Developer

    Glad I could help 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.