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.
-
AuthorPosts
-
November 9, 2017 at 2:56 am #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: ddddif 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.
November 9, 2017 at 9:53 pm #420307Tom
Lead DeveloperLead DeveloperHmm, 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.
November 10, 2017 at 6:01 am #420674themedleb
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.
November 10, 2017 at 9:47 am #420950themedleb
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.
November 10, 2017 at 7:57 pm #421297Tom
Lead DeveloperLead DeveloperYou could do something like this:
if ( '123' == get_the_author_meta( 'ID' ) ) { echo do_shortcode( '[whatever]' ); }
November 11, 2017 at 7:33 am #421700themedleb
Wow It works, I was so worried about this, thank you Tom for your kind help and precious time.
November 11, 2017 at 8:31 am #421757Tom
Lead DeveloperLead DeveloperGlad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.