Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

“View” URL not respecting `preview_post_link` filter

$
0
0

Replies: 0

If you use a filter like this to customize the Preview URL, like this:


	function add_custom_preview_link($link, $post) {
		$args = array(
			"id"		=> $post->ID,
			"type"		=> get_post_type($post),
			"path"		=> "",
            "slug"	    => $post->post_name,
			"status"	=> get_post_status($post)
		);
		
		// If we have a slug, build path
		if($args['slug']) {
			$args['path'] = "/" . get_page_uri($post);
			
			// Use custom path for posts
			if($args['type'] == "post") {
				$args['path'] = "/news/" . $post->post_name;
			} else {
				$args['path'] = "/" . get_page_uri($post);
			}
		}		

		return add_query_arg($args, $link);
	}
	add_filter('preview_post_link', "add_custom_preview_link", 10, 2);

Then in Nested Pages mode, the “View” button on the right hand side of the page list will be a default URL. Like this for a Draft page:

http://example.com/?page_id=164

But if I’m in “Default Pages” mode, then the URL will be:

http://example.com/?page_id=164&preview=true&id=164&type=page&path=/featured/drafted-page&slug=drafted-page&status=draft

It would be very helpful if the Nested Pages preview URL respected that filter.

Also, small note, but it should probably say “Preview” on the button, not “View”, just to be more inline with WordPress.


Viewing all articles
Browse latest Browse all 59525

Trending Articles