Support » Plugin: Comments - wpDiscuz » add filter for post link

  • Resolved wpman

    (@iwpman)


    I try to edit post link in email content ,but I got blank link.How to add a filter for subscribe email ?
    Here is my code:

    function custom_url(  ) {
    	if ( $post->post_type == 'post' ) {
    		$url = "my custom link";
    	}
    	return $url;
    }
    add_filter( 'post_link', 'custom_url', 10, 3 );
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author gVectors Team

    (@gvectors-team)

    Where is the function attribute? You missed that. And the number of attributes should be set correctly or not at all. Try this:

    function custom_url( $url ) {
    	if ( $post->post_type == 'post' ) {
    		$url = "my custom link";
    	}
    	return $url;
    }
    add_filter( 'post_link', 'custom_url', 10 );
    wpman

    (@iwpman)

    Thanks,It work!

    wpman

    (@iwpman)

    This is my permalink structure:
    http://www.domain.com/blog/%post_id%/%postname%/

    I want to replace it with http://www.domain.com/blog/%post_id%/ and only in email content,but it doesn’t work.
    Here is my code:

    
    function custom_link( $url, $post, $leavename=false) {
    	if(is_single()){
            $url = str_replace($post->post_name.'/','', $url );
    	}
    	return $url;
    }
    add_filter( 'post_link', 'custom_link', 10, 3 );
    

    It works but I don’t want to replace it across my site:

    function custom_link( $url, $post, $leavename=false) {
    	 $url = str_replace($post->post_name.'/','', $url );
    	return $url;
    }
    add_filter( 'post_link', 'custom_link', 10, 3 );
    
    • This reply was modified 1 year ago by  wpman.
    wpman

    (@iwpman)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add filter for post link’ is closed to new replies.