Function and usage of get_oembed_endpoint_url() in wordpress


Answers ( 1 )


    The get_oembed_endpoint_url() function in WordPress is used to retrieve the oEmbed endpoint URL for a given permalink. This function is particularly useful when you are working with oEmbed providers within WordPress.

    Function Signature

    get_oembed_endpoint_url( string $permalink = '', string $format = 'json' ): string

    Function Description

    • Purpose: The primary purpose of this function is to get the oEmbed endpoint URL based on the provided permalink. oEmbed is a protocol that allows embedding content from a website into another page.
    • Behavior: When you pass an empty string as the first argument ($permalink), the function returns the base URL of the oEmbed endpoint. This is useful when you need the endpoint URL but not for a specific permalink.


    1. $permalink (string, optional):

      • Purpose: It specifies the permalink for which the oEmbed endpoint URL is required.
      • Default Value: An empty string (''). When set to default, the function returns the base oEmbed endpoint URL.
    2. $format (string, optional):

      • Purpose: It determines the format of the response you expect from the oEmbed endpoint.
      • Default Value: 'json'. This is the most commonly used format for oEmbed responses. However, some oEmbed providers might support other formats like XML.

    Return Value

    • Type: string
    • Description: The function returns the oEmbed endpoint URL. The format of the URL depends on the parameters provided.

    Sample Usage

    Here's an example to illustrate the usage of get_oembed_endpoint_url():

    // Example 1: Get the base oEmbed endpoint URL
    $base_oembed_url = get_oembed_endpoint_url();
    echo $base_oembed_url;
    // Example 2: Get the oEmbed endpoint URL for a specific permalink in JSON format
    $permalink = '';
    $oembed_url = get_oembed_endpoint_url($permalink);
    echo $oembed_url;
    // Example 3: Get the oEmbed endpoint URL for a specific permalink in XML format
    $oembed_url_xml = get_oembed_endpoint_url($permalink, 'xml');
    echo $oembed_url_xml;

    In these examples:

    • Example 1 retrieves the base URL of the oEmbed endpoint.
    • Example 2 gets the oEmbed endpoint URL for a specific permalink in the default JSON format.
    • Example 3 demonstrates how to retrieve the URL in an XML format for the same permalink.

Leave an answer