As birgire
mentioned in the comments, "you're missing the return
part" to which you replied "how do I add that without escaping the HTML code?"
EDIT: Just a clarification. Your code should have worked, as pointed out by dswebsme. I just tested with and without a return, and both work (although returning would be preferred). The next question would be: are you putting your shortcode tag properly in to your content? e.g. [ashtopbar/]
? and it's not misspelled, right?
Leaving the section about heredoc anyway:
In PHP, you have a number of ways to get complex data (including HTML) in to a string variable. In your case, I would use PHP's heredoc syntax, as you can put virtually anything inside of it and not have to escape the syntax:
<?php
function choose_ashtopbar() {
$html = <<<HTML
<img src="/images/flag_globe2.png" class="ttupmg" />
<div class="dmzeus">
<ul>
<li class="f-selection">London
<ul>
<li>New York</li>
<li>Paris</li>
<li>Milan</li>
</ul>
</li>
</ul>
</div>
HTML;
return $html;
}
function register_ashcodes(){
add_shortcode('ashtopbar', 'choose_ashtopbar');
}
# I'm guessing init has already run by this point
# add_action( 'init', 'register_ashcodes');
# Use a different hook or just register your code
register_ashcodes();
Essentially, your original code was just echoing the HTML when add_shortcode
ran the choose_ashtopbar
function, which is probably not what you wanted.
return
part of the shortcode's callback.