Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Admin Page Previews when using subdomain WordPress

  • SOLVED

Our WP files are in folder - let's call it abc. So our website is really at the subdomain abc.domain.com, but by using redirect, users access our website at www.domain.com.

Everything works, except when the wp-admin clicks to preview a page. When the wp-admin logs in and all of the pages in the admin portal are at abc.domain.com. But when the preview page is created, WP displays the URL with www instead of abc, so we have to manually change the www to abc in the browser.

I'd like to make a change in an htaccess file to have a redirect just for these preview pages so we don't have to manually change www to abc.

Answers (1)

2014-09-20

timDesain Nanang answers:

1. go to your wp-admin
2. click general setting under settings menu
3. set WordPress Address (URL) with: http://domain.com/abc (if the folder is <strong>abc</strong>) or http://domain.com/abc.domain.com (if the folder is <strong>abc.domain.com</strong>)
4. save
5. update the permalinks setting under settings menu


SethT comments:

I had already tried that and it does not work because it changes the address for everyone. I only want this to work for page preview for admin.


SethT comments:

For future answers - please note that I have specified that I want redirect code for the htacess file to apply a redirect only for admin for preview pages.


timDesain Nanang comments:

You can using the hook instead of htaccess (see the screenshot).

put this code into theme's functions.php

add_filter( 'preview_post_link', 'wpq_preview_post' );
function wpq_preview_post() {
global $post;

//change sub.domain with yours
$preview = 'http://sub.domain.com/?p='.$post->ID.'&preview=true';

return $preview;
}

add_filter( 'post_updated_messages', 'wpq_update_msg' );
function wpq_update_msg( $messages ){
global $post;

//change sub.domain with yours
$preview = 'http://sub.domain.com/?p='.$post->ID.'&preview=true';

$post_type = get_post_type( $post->ID );

$obj = get_post_type_object( $post_type );
$singular = $obj->labels->singular_name;

$messages[$post_type][10] = sprintf( __( '%s draft updated. <a href="%s" target="_blank">Preview %s</a>'), $singular, esc_url( $preview), strtolower( $singular ) ) ;

return $messages;
}