I am using two plugins one of which is Thumbs Rating which have have a shortcode like this for example in order to display the thumbs rating option:

The code bellow is to be used in the templates files but I would like to have the option of using functions like the bellow and related ones inside posts using a shortcode if possible.

<?=function_exists('thumbs_rating_getlink') ? thumbs_rating_getlink() : ''?>

I add this into my post but it doesnt show instead gets parsed as normal text.

Is there a way to convert the code above into a shortcode something like [thumbsrating] which I can use in my posts. ( I want to paste the shortcode at a specific spot inside my post this is the reason for doing this )

Edit: Here is the code I had created with shortcode API but it didnt work:

    function rating_function() {
  return '=function_exists('thumbs_rating_getlink') ? thumbs_rating_getlink() : ''';
add_shortcode('rating', 'rating_function');

The result I got by adding the shortcode [rating] in my post was the return as text and not executed as PHP.

Any suggestions? Thanks

  • 1
    It seems like you have not take a look to the Shortcode API. Go there, read, try and come back if you need help. – cybmeta Jun 13 '14 at 17:13
  • I actually did try but since it didnt work, I thought it was a wrong approach. I have updated my post with the code I had used in functions.php. If you see any problems with it let me know please. – Jack Stanson Jun 13 '14 at 17:39

Try replacing your shortcode function with following code:

function rating_function() {
    if (function_exists('thumbs_rating_getlink')) {
        $content = thumbs_rating_getlink();
    return $content;
add_shortcode('rating', 'rating_function');
| improve this answer | |
  • Thank you it works great, one thing I have is the output being displayed in the very top but that is another issue I am reading more about it right now, will update the comment soon. – Jack Stanson Jun 23 '14 at 2:10
  • Edited the answer to show also the possibility for anyone not getting the output in their desired spot but instead at the very beginning, I hope it helps someone in the future reading this. – Jack Stanson Jun 23 '14 at 5:43

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.