Why is $wp->request empty in WordPress 6.0?

What is the correct way in WordPress to obtain the current page url? You don’t, WP has never provided a way to do this, the closest is get_permalink which provides the canonical URL of the current post. What you’ve been using is unofficial, and never gave you the actual URL as it only appended the … Read more

URL renaming issue

When I go to www.riyachting.com, I get redirected to riyachting.com. Some browsers remove the fragment (part after the #) of the URL in this redirect. Chrome keeps the original fragment and the lightbox works. Safari removes it and the lightbox doesn’t work. So either use the final URL in your link, or use something else … Read more

Block direct url enter

Preventing users from entering URLs manually in the address bar is not possible in WordPress, or from any site, for that matter. It can only be done via a browser plugin. However, redirecting users or displaying a 404 page for a certain URL is easy to do and there are several WordPress plugins for blocking … Read more

hide wp-content from urls

You don’t need a separate rule in your .htaccess. Add … define( ‘WP_CONTENT_DIR’, ‘YOUR_LOCAL_PATH’ ); define( ‘WP_CONTENT_URL’, ‘YOUR_PUBLIC_PATH’ ); … to your wp-config.php. Do not write into wp-settings.php. This file will be overwritten during the next update – never touch a core file.

How to properly print a 404 error without redirecton? (i.e. keeping the current URL)

You should be using a filter outside of your template for this: add_filter( ‘template_include’, ‘wpa62226_template_include’, 1, 1 ); function wpa62226_template_include( $template ){ if( is_page( ‘some-page’ ) ) : global $wp_query; $wp_query->set_404(); status_header( 404 ); $template = locate_template( ‘404.php’ ); endif; return $template; } Your code is executed before the template is loaded, so it becomes … Read more

How do I Redirect a WordPress Page?

I’m sure there is a more elegant way of achieving your desires, however this method does work. Just tested it. /** * Redirect pages from array. * * @author Michael Ecklund * @author_url https://www.michaelbrentecklund.com/ * * @return void */ function redirect_pages() { // Page from => Page to $redirect_pages = array( ‘wordpresspage’ => ‘/wordpress-page’ ); … Read more