Create path alias programatically when node is created
Instead of using hook, Pathauto module should be used where you can define specific pattern how aliases are generated per content type (at /admin/config/search/path/patterns). In there you can use replacement patterns or code your own. It's much cleaner approach.

Otherwise you can try hook_node_presave($node) and change the alias directly:

$node-&gt;path['pathauto'] = 0; // Required only if Pathauto is enabled.
$node-&gt;path['alias'] = "foo/bar";


or use the path_save(&amp;$path) function directly as below:

$path = array('source' =&gt; "node/$node-&gt;nid", 'alias' =&gt; 'foo/bar');
path_save($path);