Adapting functions from Genesis theme

Adapting functions from Genesis theme