Yea before the first world war one of the more famous uses of tenches against numerically superior enemies was done by Osman Pasha an Ottoman General in the Russio-Turkish War in which Osman Pasha with 30,000 troops defended a passage\village in Bulgaria called Plevne for a total of 6 months greatly turning the favor of European Support from Russian to Ottoman.
He aas tasked to head to an Ottoman fort and reinforce it woth some 10,000-15,000 tropps. By the time he reached within 70 kilometers the fort had capitulated to the Russian army. Osman pasha took up the position of Plevne denying the Russuans a very impprtant passage way into Bulgaria.
The Russian general sent a scputing column to take tbe town of Plevne but was repullsed. Osman Pasha realized that the Russians would be coming in force. Thuse he began to mark the ground, burry his artillary underground (so they would be able to withstand counter battery canon fire) and used his artiallry for out of sight fire. He placed rifle markers, built zig zag trenches and made an in depth defense.
His defe se became so furious that the entire Russian and Romanian army held siege to his encampment totallying 140,000 men greatly gaining Ottoman sympathy and turning European Great power support pver to the Ottoman cause denying Russia any real gains in the Balkans for 40 years greatly tarnishing Russian morale.
At the end of the battle of Plevne the Russian Tzar himself spoke to Osman pasha asking "Why didn't you surrender?" To which he replied "My government didn't give me guns so I could throw them down and surrender in the face of the enemy". He was treated with full honors. His forces caused a total of 40,000 casualties and devestated the Russian advance buying the Ottomam empire time in the politcal arena and denying Russia an easy victory. The year is 1878 by the way so no machine guns. The Ottoman Army was equipped woth Winchester repeating rifles for close range and henry martinis for long range. The soldiers rapidly switched weapons and for the first time repeating rifles began to be adoptwd by European armies. His trench lines oversaw one amother denying any territoey Russian troops overcame and his own artillary was placed so tbey could hit those positions as well.
Also please excuse my horrendous spelling writing from my mobile phone.