How to pin any folder to the taskbar in Windows 10 and 11
This tutorial will show you step by step how to pin any folder to the taskbar in Windows 10 and 11.
Steps

1. Right-click on an empty space on your desktop, go to New, and then click on Shortcut.

2. Enter the following text:
explorer.exe "full path to folder"
For example:
explorer.exe D:\Pictures\Screenshots

Note: if the name of a folder contains spaces, then you will need to enclose the whole path in quotes (""), like in the example below.
explorer.exe "D:\Pictures\My Screenshots"

3. Click on the Next button.
4. Enter a name for the shortcut.

5. Click on the Finish button.
As you probably already noticed, the shortcut has the same icon as File Explorer (Windows Explorer), which may cause confusion and accidental clicks, especially if you also have File Explorer pinned to the taskbar.
So it's probably better that we'll change the icon for the shortcut.
6. To change the icon for the shortcut, right-click on the shortcut and then click on Properties.

7. Click on the Change Icon button.

8. Select an icon.
9. Click on the OK button.

10. Click on the Apply button.
11. Click on the OK button.
So now that we've changed the icon, it's time to pin the folder shortcut to the taskbar.
12. To pin the folder shortcut to the taskbar, right-click on the shortcut and then click on Pin to taskbar. If you're using Windows 11, right-click on the shortcut > Show more options > Pin to taskbar.

The folder is now pinned to the taskbar.
You can now delete the newly created shortcut from your desktop, as it is not needed anymore.
Related:
How to change the color of only the taskbar in Windows 10
How to make the Windows 10 taskbar more or fully transparent
How to remove items from the Windows 10 taskbar
How to pin a batch file to Windows 10 or 11 taskbar or start menu