Advanced MyRP, how to position the comment embeds.

A fairly common question in the support area is one about the comment form hooks. In MyReviewPlugin, under the Setup Embeds > “Ratings in Comments” menu (and actually, this advice applies to other form hooks such as comment fields) you can instruct MyRP to automatically include the star rating fields (options, for the user of your site to pick) in the comment form.

But here’s the gotcha: in many modern themes, the comment_form hook occurs underneath the <input>┬átag which submits the form. This is why hen you use plugins that add fields to your comments form, you find that they are underneath the “post comment” button: rarely is this what you really want, but this is how many of the most popular themes are designed.

Luckily, there are many ways to fix this:

Option 1: Move the comment_form hook. If you open your theme’s comments.php file (go to Themes > Editor, and select the file on the right labeled comments.php), you will see the code that outputs the comments area. In “modern” style themes, a function called comment_form(…) is called to output the actual form, but in older themes, you’ll find the form, complete with >form< tags, and you’ll find a block that looks like this:

<?php do_action("comment_form"); ?>

This is where your MyRP comment form hooks are going to go, so cut that piece of code, and move it up to above the code that looks something like this:

<input type="submit" ... value="Post Comment" />

This will move the comment fields to be above the Post Comment button (if you want to put them somewhere else, such as above the Name field, or above the comment textarea, feel free to customize!)

Option 2: Hook one of the notes positions instead.

In newer themes, particularly one’s that the above method doesn’t work for, you’ll find code that looks like this (this is excerpted from the included WordPress theme Twenty-Eleven, but it is often already more complicated than this)

<?php comment_form(); ?>

This function is documented on the WordPress website, as taking a parameter in the first spot called $args. In simple terms, what that means is simply that you can tell it how to behave by creating an object that contains a set of parameters. There are two primary locations that you can use to output things in this $args array, one is called comment_notes_before and the other comment_notes_after.

So what we’re going to do, is call a MyReviewPlugin API function (MyReviewPlugin API, or MyRP/api/standard.php in your plugins files) called myrp_api_ratings_form_table. Most MyReviewPlugin API functions take two parameters, one that indicates the post ID (or null to use the current post) you wish to get the data for, and one that indicates whether to RETURN (allow it to be used in other code) or to ECHO (put it on the website right now) the data. In this case, we want to return, because we want to use it in the $args array mentioned above.

The code for this method then looks like (for the “comment_notes_before” option)…

$args = array("comment_notes_before" => myrp_api_ratings_form_table(null, true));

Or, you can switch out comment_notes_before with comment_notes_after to use the other location:

$args = array("comment_notes_after" => myrp_api_ratings_form_table(null, true));

Themes often manipulate their comment_forms to behave differently, so try both locations, see which one works best for you.

When you call API functions, like you are here, you will want to go to MyRP > Setup Embeds > Ratings in Comments in the WordPress administration area to make sure you turn off the automatic embeds. The MyRP online quickdocs have more information about API (manual) vs. automatic embeds.

Option 3: Just call the ratings form directly, with caveats. The third option (which is really a more general case of the above option), is simply to call the API call <?php myrp_api_ratings_form_table(); ?> where-ever you want the form. The caveat here is that it must appear after the <form> tag, but before the closing </form> tag in the comments field. If you can see the form tag in your comments.php, you can simply copy and paste the code anywhere in there.

Solving this problem for plugins that don’t provide an API function may not be as easy — you’ll want to look in to your theme’s functions.php file, to see if there’s somewhere that defines the comments form. If you can find that, you can use option 1 above to move the do_action call.

As always, if you have any trouble with any of that, feel free to submit a support ticket. We will not be able to help you via blog comments, so please do use the support system at to get assistance!

Leave a Reply

Your email address will not be published. Required fields are marked *


Comments on the MyReviewPlugin blog are moderated and are expected to remain on topic. Feature requests, technical support, inquiries, etc. should be directed to the proper support channels and will not be approved on the blog.