最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom CSS based on the Author of a Post

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论