A few things:
- You’re running your
add_shortcode()
function inwp_head
. You don’t need to do that. - Your
life_shortcode()
function is returning a value, not echoing it. So it’s not going to be caught by the output buffer andob_get_clean()
will return nothing. wp_list_categories()
is echoing, so is not going to be properly put into$mycats
and is going to be output at the top of the page whenever your shortcode is used.
The proper way to organise this code would be:
function life_shortcode() {
$args = array('title_li' => '', 'echo' => false);
$mycats = wp_list_categories($args);
return '<div class="conmenu"><a class="salit" href="https://wordpress.stackexchange.com/lifestyle/"><i class="x-icon-home" data-x-icon=""></i></a><ul>' . $mycats . '</ul></div>';
}
add_shortcode( 'lifemenu', 'life_shortcode' );
Also note that I’ve passed the function name directly to add_shortcode()
, rather than use an anonymous function that calls the original function. This way uses less code, and makes it easier for it to integrate with other plugins, if necessary.