• Hi guys,

    I have been working on a custom template and wanted to include a trackback link at the bottom of each page and post. I found a theme that already includes this functionality and copied the following code into my “comments.php” theme file.

    <?php if(pings_open()) : ?>
    	<span class="addtrackback"><a href="<?php trackback_url(); ?>"><?php _e('Trackback', 'inove'); ?></a></span>
    <?php endif; ?>

    But the links that are generated do not appear to be correct.

    On the page: https://localhost:8080/blog/?page_id=2
    The trackback link is: https://localhost:8080/blog/wp-trackback.php?p=2

    If the trackback link is clicked I get the following error message in XML format:

    <response>
    	<error>1</error>
    	<message>I really need an ID for this to work.</message>
    </response>

    On the page: https://localhost:8080/blog/?p=16
    The trackback link is: https://localhost:8080/blog/wp-trackback.php?p=1

    Which I think is probably correct.

    Could you please advise me on this issue?

    Many thanks,
    Lea Hayes

Viewing 1 replies (of 1 total)
  • Seems the get_trackback_url does not take into consideration when a page is displayed and not a post as it always returns

    $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;

    The page trackback should be changed to

    '/wp-trackback.php?page_id=' . $id;

    which worked fine for me.

    To fix this issue, add the following to your functions.php file.

    add_filter ('trackback_url', 'fix_page_trackback_url', 15);
    if (!function_exists('fix_page_trackback_url')):
    function fix_page_trackback_url ($trackback_url)
    {
      if (is_page()):
        return str_replace ('?p=','?page_id=', $trackback_url);
      else:
        return $trackback_url;
      endif;
    }
    endif; //fix_page_trackback_url

    Hope this helps…

    Note: not sure if it still works when permalink structure is customized!

    /Kaf

Viewing 1 replies (of 1 total)
  • The topic ‘How to use trackback_url() function properly?’ is closed to new replies.