0

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

2
  • 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, 2014 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. Jun 13, 2014 at 17:39

1 Answer 1

0

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');
2
  • 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. Jun 23, 2014 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. Jun 23, 2014 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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