I'm kinda new to Wordpress and CSS, I hope you guys can help me out.
I want to change the position of the sitelogo .site-branding
of all the posts under a specific category.
I can change the site-branding
in my style.css to my liking but it effects the whole site including all pages, posts and category's.
.site-branding {
left: 50%;
position: absolute;
top: 40%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
Hope you guys can help me out.
Thanks in advance.
You will likely need Javascript and Jquery for this.
So if this is your URL structure: www.mysite.com/home/category/,
Assuming you are running a child theme on your wordpress instance (which if you are not, you definitely should) you can add this script at the bottom of your header.php file.
Thanks for the effort, but I have had a little help and fixed the problem.
I added this filter to my functions.php
That filter will add the category name as a class to the
body
on single posts.For example, if the category is called News, it will add
category-news
to the body as a class on single posts.Once that’s done, you can use that body class to only target
.site-branding
on single posts in the News category like this:WordPress gives you the ability to target the category by adding its name to your stylesheet (usually "category-x") and then you can uniquely target any and all categories in your css.
Here's a great step by step article for targeting this class in your css.
An example might be:
With category-agriculture being the class you want to target like so:
For that I think you will have to add a PHP conditional in your header.php that checks if the current post is in that specific category, and then add another class to your logo tag that changes it's position.
Would be something like this:
Wordpress may add category as a class to body tag. If it is so for your theme than you may add specific css rule for category.