Home Add Food2fork Recipes to WordPress with Shortcode

    Add Food2fork Recipes to WordPress with Shortcode


    Food2fork is one of a number of recipe websites that wallpapers the Internet, and it’s the first of many recipe websites that’ll be the target of our attention in coming months. The site’s API has two main API functions: the first will search indexed recipes; the second will extract limited details of an actual recipe. In this article we’ll use the second API function to build a basic recipe on your website.

    Food2fork is used primarily to direct traffic to other recipe websites – so it’s not overly functional. To that end, the recipe’s directions (method) won’t be returned by the API, and the method isn’t visible on the F2F website. If you’re after a full recipe solution we’ll be providing far better options in the future.

    See also: Example PHP Functions to Return Recipe Methods From Cooking Websites (link).

    We’re returning the limited F2F data in a very basic manner. If you plan on using this code it’s expected that you’ll style the returned HTML with appropriate markup .

    The Result

    To include the basic recipe for a Chocolate slice we’ll use the shortcode of [food2fork r="http://food2fork.com/view/Caramel_Slice/cef370"]. The result:

    Caramel Slice


    200g of plain digestive biscuits, crushed
    100g of unsalted butter, melted
    2 tablespoons of desiccated coconut (optional)
    125g unsalted butter, extra
    400ml of tinned sweetened condensed milk
    90g of caster sugar
    3 tablespoons of maple syrup/golden syrup
    250g of dark chocolate, chopped
    2 teaspoons of oil

    Method: View the full recipe: BBC Good Food

    Recipes powered by Food2Fork

    We could have optionally used just the recipe ID ([food2fork r="cef370"]).

    WordPress Shortcode

    Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

    If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

    Shortcode Attributes


    The r is the recipe ID. This is either the full URL to the recipe page or the last string of digits after the last backslash.


    The apikey is required to make queries and can be obtained from the website .


    Attribution is provided in the code by default. However, to create a link back to the food2fork website use attributionlink="'1" in your shortcode. It is false by default.


    The recipe isn’t formatted so it’s expected that you’ll style it up yourself… such as rendering the ingredients in a list. It’s also not returned in its entirely – likely to protect the origin website’s copyright. Shortcodes we have planned for the future lets you return far more feature rich results.

    The function will only query the API the first time it requests a particular recipe. Recipe text is then cached locally in your WordPress database and called upon only when required. Consider caching the image locally by either copying it to another directory or importing it into your WordPress library.

    The food2fork API is free for personal use for up to 500 queries per day. There’s a fee for commercial purposes but given the limited results it’s not a particularly wise investment.

    Shortt URL for this post: http://shor.tt/1XHb