How to get the block by string ID I have a block, and want to print it in the template. I use the following code:

 $block =  module_invoke('block', 'block_view', '6');
 print render($block["content"]);


It works, but in module_invoke() I use the ID of the block in the database, which is very bad. Is it possible to assign the string ID to the block and use it instead?

If it's impossible, how can I use strings instead of numbers?
There's no built-in function for loading a block by string, but you can use a simple SQL query to get the ID of the block using a string.

$block_name = "Your block name";

$block_id = db_query("SELECT bid FROM {block_custom} WHERE info=:info", array(":info"=&gt;$block_name))-&gt;fetchField();

$block =  module_invoke('block', 'block_view', $block_id);
print render($block["content"]);