How can I change the page that the 'view' action links to on the list post screen for a custom post type?


I've got it to work with normal post types using the below code but where do I define the custom post type?

function change_link($post_url,$post) {
    return '/video?id='.$post->ID;

2 Answers 2


By adding a filter to the 'post_link' hook. See the get_permalink() function for more info.

For custom post types, you can use the 'post_type_link' hook.

It's a lot easier if you follow the source code (this is for v3.0):

  • See updated answer.
    – scribu
    Oct 6, 2010 at 9:28

Based on the update of your question:

function change_link( $permalink, $post ) {
    if( $post->post_type == 'video' ) { // assuming the post type is video
        $permalink = home_url( 'video?id='.$post->ID );
    return $permalink;
  • I tried that before and it doesn't work. It just removes the permalink altogether for my blog posts (because the filter is still being applied to standard 'posts' but the function's not returning anything) and doesn't change the video custom posts.
    – fxfuture
    Sep 30, 2010 at 17:49
  • 1
    I edited my answer. I may have been very tired when I wrote it. :)
    – sorich87
    Sep 30, 2010 at 18:24
  • No problem! Your code works for normal posts if I change ($post->post_type == 'post') but when I use 'video' or another of my custom post types it doesn't work?
    – fxfuture
    Sep 30, 2010 at 20:06
  • I'm probably missing something obvious, but why is manipulating the post_link to add a query var for the custom post type even necessary? I've never had to do this - my "view" links (and all other permalinks for that matter) already have the post type inserted in the URL...
    – somatic
    Oct 22, 2010 at 17:52
  • He wanted all the videos posts to go to the same page (not to their default page) and the post id passed in the URL. E.g.: mysite.com/video?id=23, mysite.com/video?id=54, etc.
    – sorich87
    Oct 22, 2010 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.