The get_trackback_url() WordPress PHP function retrieves the current post’s trackback URL.
Usage
To use the get_trackback_url() function, simply call it within the loop:
$trackback_url = get_trackback_url(); echo 'Trackback URL: ' . $trackback_url;
Parameters
There are no parameters for this function.
More information
See WordPress Developer Resources: get_trackback_url()
Examples
Display the trackback URL in a post
This example displays the trackback URL in a post’s meta information.
// Display the trackback URL $trackback_url = get_trackback_url(); echo '<div class="post-meta">'; echo 'Trackback URL: <a href="' . $trackback_url . '">' . $trackback_url . '</a>'; echo '</div>';
Add trackback URL to post footer
This example adds the trackback URL to the post footer.
function mytheme_add_trackback_url() { $trackback_url = get_trackback_url(); echo 'Trackback URL: <a href="' . $trackback_url . '">' . $trackback_url . '</a>'; } add_action('the_content', 'mytheme_add_trackback_url');
Display trackback URL only if enabled
This example checks if trackbacks are enabled for the current post and displays the trackback URL if so.
if (pings_open()) { $trackback_url = get_trackback_url(); echo 'Trackback URL: <a href="' . $trackback_url . '">' . $trackback_url . '</a>'; }
Create a function to display the trackback URL
This example creates a function to display the trackback URL, making it easier to reuse across your theme.
function display_trackback_url() { $trackback_url = get_trackback_url(); echo 'Trackback URL: <a href="' . $trackback_url . '">' . $trackback_url . '</a>'; } // Use the function within the loop display_trackback_url();
Display trackback URL in a list of post meta information
This example displays the trackback URL in a list of post meta information, along with the author, date, and category.
echo '<ul class="post-meta">'; echo '<li>Author: ' . get_the_author() . '</li>'; echo '<li>Date: ' . get_the_date() . '</li>'; echo '<li>Category: ' . get_the_category_list(', ') . '</li>'; $trackback_url = get_trackback_url(); echo '<li>Trackback URL: <a href="' . $trackback_url . '">' . $trackback_url . '</a></li>'; echo '</ul>';