Site logo

Archived topic

Show a specific thing in single post when a specific author wrote that post

6 replies · Started by themedleb on November 9, 2017

Viewing posts 1–7 of 7

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.

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.

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.

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.

You could do something like this:

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

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

Glad I could help :)

This archived topic is closed to new replies.