Function and usage of get_linkrating() in wordpress


Answers ( 1 )


    The get_linkrating() function in WordPress is a legacy function used to retrieve the value of a link's link_rating field. Here's a detailed explanation of its function and usage:


    • Name: get_linkrating()
    • Purpose: To retrieve the value of the link_rating field from a link object in WordPress.


    • This function is part of WordPress's legacy code, which means it might be outdated or no longer the best practice for modern WordPress development.
    • It specifically targets the link_rating field within a link object.
    • The function is closely associated with the sanitize_bookmark_field() function, which is used for sanitizing the fields of a bookmark or link object in WordPress.


    • $link (object): This is a required parameter.
      • Type: Object
      • Description: The link object from which the link_rating field value is to be retrieved. This object represents a link stored in WordPress.


    • Type: mixed
    • Description: The function returns the value of the link_rating field. If the link_rating field does not exist or the function is unable to retrieve it for any reason, it returns false.

    Sample Usage:

    // Assume $link is a link object obtained from WordPress
    $link = /* some code to get a link object */;
    // Retrieve the link rating
    $link_rating = get_linkrating($link);
    // Check if the link rating was successfully retrieved
    if ($link_rating !== false) {
        echo "Link Rating: " . $link_rating;
    } else {
        echo "Link Rating not available.";

    In this example, $link is a link object which you would typically retrieve from WordPress's database or link management system. The get_linkrating() function is then used to extract the link_rating value from this object. If the value is successfully retrieved, it's printed out; otherwise, a message indicating that the link rating is not available is displayed.


    • As a legacy function, it's advisable to check if there are more modern alternatives available in the latest WordPress documentation.
    • Always ensure that the link object passed to the function is valid and correctly structured to avoid errors or unexpected results.

Leave an answer