Politics is tricky. I have/had to do a lot more public relations. Starting/running book/video clubs, making time for 1:1s with coworkers, I even did a 2+ year stint of starting off the morning slack chats with a dad joke, that was very appreciated. There are many ways to be productive, but I had to find ways to stay noticed, likable, relevant, and appreciated outside the pull requests. As my former manager said, if no one remembers who you are, you will become just a line item on the payroll.
I think your experience is really interesting, because as a dev our work can be hard to measure, unless you're working on something huge and very visible, so this interpersonal part of the work becomes very important, kinda like your manager said, you have to be remembered for something more than just "that guy we pay to make code".
I do something pretty similar. Friday's I will somewhat regularly send a dad joke or meme. These of course stay non-political and very SFW.
On a somewhat serious side. I try to regularly send "tips". If I learn something that I think is beyond cool I'll send an email teaching that new cool thing. If it can't be done in an email I'll setup small sessions to teach that over Zoom. I prefer Zoom because it's more impactful as far as being "seen" and not just another email.
Relaying what I've learned (even basic things) works really well, at least my regular 1:1's and reviews support this view.
This allows you to bypass the politics situation pretty well. Interact professionally with the people you need to, get your work done, and get your social and drama needs met elsewhere, like with real friends and family :-P
If half the team is wfh it just seems like those in the office will be in the loop more consistently, especially if the team lead is also in the office. There's a lot of questions I feel comfortable asking casually if the person I want to ask is nearby but not by sending them an email or during a meeting.
There is this bot on slack called donut that every company I've been uses. Basically it prompts 2 or more random people to catch up every week or how often you think not annoying. I don't think I had more than that back in the office days but you could send slack messages to people how often you want if you like more.
In my team, most of the times, anything important needs to be sent to the channel for transparency and more chance of getting picked up. Private messages are not expected to be as important nor get an immediate reply so people won't feel bothered when you send one. Then there are also things more purposefully async such as github issues and wikis.
In a remote environment you have no idea if you're interrupting someone when you give them a call, so you need a proper reason to call someone. People discuss things in closed conference calls, chat rooms and email chains, so if they don't invite you you will never learn about any opportunities yourself.
If you're very confident in yourself and your work though this probably is less of a problem.
I was a remote employee (IC) for about 12 years, and this was a recurring problem. I was one of a handful of remotes in a global team across several time zones, so at some level everybody had to deal with this problem: I didn't have a good handle on the office politics in the US, but the people in the US had just as tenuous a grip on the office politics in Singapore, and so on.
Somehow it usually worked out OK, but we had a director who was very good at shielding us from the more distracting stuff, and we were working on a chronically understaffed, mission-critical, unglamorous, profitable product, so it sort of attracted "just do the work" types.
The OP, however, is a consultant, which brings a very different set of political considerations. Last time I did remote consulting, which was a long time ago, the biggest thing you had to worry about was budget.
Was the $2M project going to get $5M next year or $1M and why? If it's $5M you'd better be able to offer more services or they might push you out in favor of a bigger shop; if it's $1M you'd better make sure you have an internal champion to make sure you still get some of the work; and if you think you can't influence the decision you're not paying attention.
Back then, consultancies would have people on staff just to take all the meetings and drink the drinks and press the flesh and know these things. I'm talking about shops with maybe 10-20 people. I don't know how it works now, but I would bet tomorrow's lunch that whoever still has those people makes more money than whoever doesn't.
(I was a solo consultant, and my lunch was a lot more modest.)
I got a 35K raise recently - and all I did was ask - at my current job where 90% of the people are remote. The entire time I've been employed here, I've made sure to constantly mention to my manager how much I've improved things; that's what I mean by "sell your skills".
Basically from my experience, it's made no difference whether I'm in the office or working remotely; my value is recognized all the same.
EDIT: BTW I'm not a "Rockstar Dev" or any bullshit like that. My skill level is either on par or slightly lower than my colleagues. I just make sure to focus on solving tangible business problems and keep constant open communication with my team or stakeholders.