Kipling wrote "If" as a tribute to Sir Leander Starr Jameson who was a British statesman who led a failed attempt to seize a Boer armory and incite an insurrection among those opposing the Boers. Kipling also wrote this as lesson to his son on how to be an honorable man.
"If" is a didactic poem which means it is meant to be a lesson and provide instruction - in this case to anyone who reads it and/or, from Kipling's perspective, to give advice to his son.
In the first stanza, the speaker instructs the reader to be confident but be open to criticism from others.
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
The speaker also encourages patience, honesty, and humility. These qualities have a balanced approach. For example, be confident but humble. Have strong convictions but be open to new ideas.
Kipling continues with this kind of balanced advice. In stanza 2, he opens with instructions to be a dreamer but do not be dominated by your dreams. In the third stanza, Kipling preaches resilience, being willing to persevere especially when all seems lost:
And so hold on when there is nothing in you
Except the Will which says to them: "Hold on!"
The fourth stanza also includes balanced advice (walk with kings but don't lose touch with the "common" people). Kipling concludes by saying that "if" you (reader or in this case, his son) can live by this advice, then the world will be yours.
Yours is the Earth and everything that's in it,
And--which is more--you'll be a Man, my son.