Custom CSS based on the Author of a Post

I have a site where users can claim a business listing. The listings that are not claimed all have the same author.Onc

I have a site where users can claim a business listing. The listings that are not claimed all have the same author. Once they claim them the author becomes the owner of the business. The button sadly does not get removed, that is built in the theme and the theme owner said that will not be added to development.

So I am looking for a code snippet that will inject some CSS onto the pages if the author of the page is not id=2 (that is the author id) This CSS would hide the class of the button which is .claim

There is also a custom field used if that is easier to target for the injection of the field.

Any help or ideas would be greatly apperciated

/

I have a site where users can claim a business listing. The listings that are not claimed all have the same author. Once they claim them the author becomes the owner of the business. The button sadly does not get removed, that is built in the theme and the theme owner said that will not be added to development.

So I am looking for a code snippet that will inject some CSS onto the pages if the author of the page is not id=2 (that is the author id) This CSS would hide the class of the button which is .claim

There is also a custom field used if that is easier to target for the injection of the field.

Any help or ideas would be greatly apperciated

https://rezrising/

Share Improve this question asked Nov 27, 2019 at 11:16 Jason AkeJason Ake 1
Add a comment  | 

1 Answer 1

Reset to default 0

Welcome to Stack Exchange!

In your theme's function.php, you can add this code:

add_filter('body_class', function($classes) {
    $classes[] = 'author-' . get_current_user_id();

    return $classes;
});

This will add a CSS class with the current author's ID to <body> which you can then target:

.author-2 .widget_bt_claim_widget {
    display: none;
}

See https://developer.wordpress/reference/functions/get_current_user_id/ for return values.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962965a4603499.html

相关推荐

  • Custom CSS based on the Author of a Post

    I have a site where users can claim a business listing. The listings that are not claimed all have the same author.Onc

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信