Try this, which uses the parse_request
hook: (you can add other conditions, e.g. check whether $wp->query_vars['name']
is not empty, if you want to)
add_action( 'parse_request', 'wpse_400900_parse_request', 1 );
function wpse_400900_parse_request( $wp ) {
// Redirect if the URL ends with a ? like https://example.com?
if ( ! empty( $_SERVER['REQUEST_URI'] ) &&
ltrim( $_SERVER['REQUEST_URI'], "https://wordpress.stackexchange.com/" ) === "{$wp->request}?"
) {
wp_redirect( home_url( $wp->request ) );
exit;
}
}
Related Posts:
- get php variable from functions php and echo it in theme template files [closed]
- paginate_links() don’t properly work in search.php?
- How to influence the information displayed on widget inside wp-admin
- Remove Container Element From wp_nav_menu() Markup
- WordPress function like is_category for subcategory? is_subcategory?
- How can I get $id variable in widget’s form function?
- Using a private method as an action callback from within a class
- Auto close (hide) custom metabox / set default state
- Does WordPress Development Mode Exist (with not minified JS)?
- wp_delete_user with username
- what is the meaning of settings_fields()
- Organize functions.php
- How to activate “Description” metabox for menu item programmatically?
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- Make WordPress size and name images for Retina.js
- How to set child post categories to parent post categories when updating parent post?
- get excerpt without images
- Pinterest Integration Using functions.php
- Adding WooCommerce to a Custom Theme – not working [closed]
- WooCommerce add_action hook results in 500 error
- Advice: Template structure – php blocks in sidebar or someting else?
- Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]
- Changing itemprop from logo to image on custom logo?
- wp_get_post_terms() returns WP_Error in functions.php but in template it works
- Removing the first image in content
- Move jQuery and Migrate to footer?
- Make menu structure match page heirarchy on page parent change
- Change Rating range in Link Manager
- function to erase swear words
- str_replace function in theme
- is_account_page() change to page slug
- Function call via ajax – can’t figure it out?
- How to add nav menu items to a specific position within a menu
- woocommerce: change default setting > is_sold_individualy function
- Help with WP gallery function, wrap gallery in div
- WordPress Menuing Question :focus
- call of javascript function to external url always blocked by cors
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- What WordPress function to use to get meta value by using meta keys?
- Force to use STRONG users password and implement rule to prevent REUSE [closed]
- Create a custom taxonomy that will be used to create and filter markers in a Google Map
- Adding an external HTML link to a post thumbnail
- Overwriting the menu break points of twentysixteen in child theme
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- How to create an onclick event on an image in a post?
- Help With Creating Shortcode
- How can I use Woocommerce $product->get_attribute in functions.php? (if at all)
- How to set default post editor based on role?
- How to hide image-url if no attachment?
- Solved: redirect to another page using functions.php
- Getting the teaser text without overriding global variables
- Problem in using Customizer
- Ajax resetting my global variable
- Problem enqueuing scripts on not single posts
- referencing the current user in a page i created in wordpress
- is_main_query() always returning false
- How to show ACF value under post/page title in wp-admin
- Undefined variable issue for wp_get_attachment_image_url
- Counting posts and trigger it [closed]
- ACF Flexible in TCPDF
- How do i tweak my wp Post title base on category of the post
- Why isn’t comment validation working?
- I’m creating a online store for my website, my aim is to add description to products in home page only how can i achieve it?
- modifying every other element’s class inside while loop
- Adding Custom Body Class for Page: Shop
- “Conditional query tags do not work before the query is run. Before > then, they always return false. “
- Change ‘Categories’ to ‘Topics’
- Is it possible to use ‘wp_insert_post’ function within a for loop?
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- Code I am placing in the wp_footer is going outside the entire HTML frame!
- How to assign results to variables?
- Restoring pages in wordpress
- Redirect after login to current URL
- Restrict certain roles registrations by domain
- Replacing term/taxonomy archive pages with search queries
- Return ACF Field value function
- Best way to add image to recent posts widget?
- Different body image backgrounds on different pages, posts and categories
- Hide certain post types from editors
- Language switcher for subdomains
- Function to draw random image from specified category destroys site logic – why?
- Issues with add_query_arg() not passing a variable
- Add Function For Instances of Custom Text in Multiple Category IDs to display in post content
- Move captions under gallery images in twenty fourteen theme
- Force changing the Site Title and add link
- create submenu page – error function not found or invalid function name
- How to add a class name to the ancestor of a post?
- Undefined offset: 2
- is_user_logged_in() isn’t working
- Retrive post by tags PHP code
- Sorting date results from a query
- Using is_plugin_active within functions.php
- Button generate a random URL [closed]
- Add custom css to theme
- How do I add functionality to images?
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- Different ads on every website on multisite environment
- How to get variable from other function inside class function using add_action for Ajax call