1

Seems the only way to get a shortcode to function in Joomla is via placing it in an article, unlike 'do_shortcode' in WordPress.

So, if my shortcode is for example, {msg userid=123}, how would I get it to dynamically grab the user id of the creator of the content?

I've tried the following, but no luck...

<?php
echo '<input type="hidden" id="userID" value="'.$resUid.'" />';
?>

along with the javascript...

<script>
    var uid = jQuery("#userID").val();
    jQuery(".content").append('{msg userid='+uid+'}');
alert('uid:'+uid);
</script>  

I can understand why it doesn't work, but is there any other method that maybe I don't know about like 'do_shortcode' in WordPress

2

The Joomla equivalent of do_shortcode is

$text = JHtml::_('content.prepare', $text);

Joomla doesn't implement short codes in the same way as WP. It runs content plugins on the article content, and the method above does the same thing for 3rd party extensions.

That being said, it doesn't sound like the problem you have has anything to do with shortcodes, nor does the code you posted seem to make any sense to me. Perhaps you would be better off to change your question to explaining your real problem.

| improve this answer | |
  • That worked! Surprising that I couldn't find that info anywhere since it seems like something that would be a common need when doing custom Joomla work. I re-worded the title into more of a question. The code I wrote does make sense and work... it just doesn't 'execute'. But that's kind of expected since it doesn't get 'prepared'. Thanks for such a simple but perfect answer. – tim92109 Dec 9 '17 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.