I have added a power switch to turn on/off my raspberry pi 4. When I use this switch the fan connected still remains on. How would I add something to my script when the switch is toggled to turn off this fan. I read this post here: How to operate a cooling fan using GPIO pins, RaspPi2 Where one of the answers said that if you have the fan connected to %V and ground pin you can not disable the fan. This is exactly the pins I have my fan connected to (pins 4 and 6) So is there any other way I could connect the fan to be disabled when the power switch is toggled or since this information is somewhat old is possible to toggle power to these pins now on the raspberry pi 4.
You can only control a fan with additional circuitry. See https://raspberrypi.stackexchange.com/a/105820/8697 for an example.
Pins 4 & 6 are DIRECTLY connected to the input 5V supply so cannot be controlled by the Pi. However if you remove power to the Pi they should NOT have any voltage.
If the fan continues to run you have NOT removed power - this can be verified by measuring the voltage on pin 2. (Be careful NOT to accidentally connect to any other pin - especially pin 1 which is adjacent. This will instantly kill the Pi.)
If you have other powered devices connected to the Pi it is possible they are supplying power e.g. via a USB connection. This should NOT happen, and it should NOT be possible to back power the Pi. If this happens the cause is external to the Pi.