WordPress将过滤器添加到wp\u获取\u附件\u链接

WordPress将过滤器添加到wp\u获取\u附件\u链接,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我需要为过滤器自定义类,以获得附件链接。所以我想说: function modify_attachment_link( $markup ) { global $post; return str_replace( '<a href', '<a class="view" rel="galleryid-'. $post->ID .'" href', $markup ); } add_filter( 'wp_get_attachment_link', 'modify_attachmen

我需要为过滤器自定义类,以获得附件链接。所以我想说:

function modify_attachment_link( $markup ) {
global $post;
return str_replace( '<a href', '<a class="view" rel="galleryid-'. $post->ID .'" href', $markup );
}
add_filter( 'wp_get_attachment_link', 'modify_attachment_link' );
函数修改附件链接($markup){
全球$员额;
返回str_replace(“,$id,$size,$permalink,$icon,$text);
}
所以我的意思是如果($permalink),我不需要为这个函数添加自定义类。

试试看

function modify_attachment_link( $markup, $id, $size, $permalink ) {
    global $post;
    if ( ! $permalink ) {
        $markup = str_replace( '<a href', '<a class="view" rel="galleryid-'. $post->ID .'" href', $markup );
    }
    return $markup;
}
add_filter( 'wp_get_attachment_link', 'modify_attachment_link', 10, 4 );
函数修改附件链接($markup、$id、$size、$permalink){
全球$员额;
如果(!$permalink){
$markup=str_replace('
function modify_attachment_link( $markup, $id, $size, $permalink ) {
    global $post;
    if ( ! $permalink ) {
        $markup = str_replace( '<a href', '<a class="view" rel="galleryid-'. $post->ID .'" href', $markup );
    }
    return $markup;
}
add_filter( 'wp_get_attachment_link', 'modify_attachment_link', 10, 4 );