WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] attachment_link filter hook not passing ID (3 posts)

  1. pbalazs
    Member
    Posted 2 months ago #

    Hi,
    I'm trying to modify the attachment permalinks with the corresponding hook, but I'm having an issue: the attachment ID doesn't get passed to the function.
    Here's my code:

    function __filter_attachment_link( $link, $id )
    {
        return preg_replace( '#attachment/(.+)$#', 'photo/'.$id, $link );
    }
    add_filter( 'attachment_link', '__filter_attachment_link' );

    I get the following error: "Warning: Missing argument 2 for __filter_attachment_link() in ..."
    Although in the Filter Reference it says "Filter function arguments: link URL, attachment ID".
    Does anybody have an idea what is the problem here?
    Thanks in advance.

  2. keesiemeijer
    moderator
    Posted 2 months ago #

    Try adding the $accepted_args parameter
    http://codex.wordpress.org/Function_Reference/add_filter

    add_filter( 'attachment_link', '__filter_attachment_link', 10, 2 );
  3. pbalazs
    Member
    Posted 2 months ago #

    Yes, that was it, thanks.

Reply

You must log in to post.

About this Topic