Mtm_consent_removed AND tracking cookies set also

Hi,

I’m using Matomo 4.2.1 that is connected to from a wordpress plugin.I implemented a custom opt-in/opt-out solution with a click on a button. I used this information: https://developer.matomo.org/guides/tracking-javascript-guide#optional-creating-a-custom-opt-out-form
means I used these function calls:

this.isUserOptedOut()
_paq.push(['forgetUserOptOut']);
_paq.push(['optUserOut']);

Now I have strange behaviour:
The user is opted-in by default. After a click on the button a “mtm_consent_removed” cookie is set and the two Matomo cookies (_pk_sess… and _pk_id…) are removed. While the user is then further surfing on the website, the two Matomo cookies are set again (with another value) and the “mtm_consent_removed” cookie is still there also. So the user is not able to opt-out.

Any ideas on that?

Best regards, Alex