Hi guys,
I know I am on legacy support but just wanted to let you know about this behaviour in case it is indeed a bug. I’ve encountered an issue with the Pro theme where the Cornerstone/Pro builder preview fails to load when using a custom permalink structure for standard posts. Specifically, I modified the default post permalink structure to include /wissen/
as a subdirectory for all standard posts. While the frontend works perfectly, the Pro builder preview throws the following error:
The preview could not load due to the iframe response being incomplete. This is most often related to a plugin conflict, or customizations introducing a PHP error.
Here is the PHP code I added to change the post permalink structure:
// Add Custom Permalink Structure for Default Post Type
add_action('init', function() {
add_rewrite_rule(
'^wissen/([^/]+)/?$',
'index.php?post_type=post&name=$matches[1]',
'top'
);
});
// Override Permalink Structure for Posts
add_filter('post_type_link', function($post_link, $post) {
if ($post->post_type === 'post') {
return home_url('/wissen/' . $post->post_name . '/');
}
return $post_link;
}, 10, 2);
add_action('template_redirect', function() {
// Check if it's a single post and not already using the /wissen/ structure
if (is_singular('post') && !preg_match('#^/wissen/#', $_SERVER['REQUEST_URI'])) {
global $post;
// Build the new URL
$new_url = home_url('/wissen/' . $post->post_name . '/');
// Redirect to the new URL with a 301 (permanent redirect) status
wp_redirect($new_url, 301);
exit;
}
});
add_filter('cornerstone_dynamic_url', function($url, $post) {
if ($post->post_type === 'post') {
$url = home_url('/wissen/' . $post->post_name . '/');
}
return $url;
}, 10, 2);
I have already flushed flushed permalinks (Settings > Permalinks), verified the rewrite rules and confirmed that /wissen/
is correctly applied. I thought I would be able to just insert absolute URLs to have a preview but this seems to not be an intended behaviour. Maybe this would be handy as a feature to have for cases like this as a fallback?
Is is definitely the forced redirect that causes the problem but I really have to make sure that the permalink without /wissen/
is not visited because of SEO reasons. The Pro loopers that show the posts seem to stick to the original link structure, instead of the updated permalinks. I have to work with the PHP code since I dont want my custom post type to be included in the change of a link.
Let me know if you can reproduce this issue and can confirm this on your end. If this is actually a user error by me, I will consider to renew my support soon.
Best
Raphael