• Resolved home2mars

    (@home2mars)


    I have multi-steps question because I am not sure what generates the behavior.

    First, little background: I am a volunteer for a Boy Scout troop without any real programming experience, so please do not make any assumption on the technical jargon.

    What code/engine/part of the WordPress (core or theme or plugin) that is involved or responsible for resolving URL if it is not specifically generated by a page/post/event/category/slug.

    Here is one example, when I append “mulch” on my url, it will go to an event with url of /event/mulch-delivery/

    Fyi, my event plugin is ‘All-in-One Event Calendar by Time.ly’. My theme is https://www.handsomeweb.com/scouts/ and my WP version is 5.0.3

    The resulting event is not necessarily first event that begins with the appended-word and not the last event as well. It seemingly random.

    But if there is no event whose slug does not start with the appended-word then I will get a 404 page

    Who controls this behavior? The search engine? If I use a search box, it will show a result page and not directly send me to a random event page.

    Here is the result of putting “mulch” on the search box: /?s=mulch

    Maybe after finding the answer to this question, I can figure out my ultimate goal.

    • This topic was modified 6 years, 1 month ago by James Huff.
    • This topic was modified 6 years, 1 month ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • There’s an internal WordPress function that determines what page to show depending on the URL that’s requested. Off the top of my head I can’t remember which one it is, but I have found it after a bit of digging a while back.

    The basics of what happens are:

    1. Check for a page/post/item that matches the requested URL completely.
    2. If not found, check for a page/post/item that is as close of a match as can be found
    3. If not found, show the 404 error page

    Basically, because you’re not calling the full URL WordPress is trying to get it’s own best guess as to what you actually want to see.

    If you want to see a particular item, you need to use the full URL otherwise you’ll always go through that default process.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thread Starter home2mars

    (@home2mars)

    Thank you for all your replies.

    Here is what I wanted to do: The fundraising teams wants to use a specific URL (/mulch) to open up to an external page troop-1128.mybigcommerce.com/

    I have set up similar external url in the past using this piece of code in the function.php file
    *************************

    
    //https://www.namehero.com/startup/how-to-redirect-a-page-in-wordpress-plugin/
    function redirect_page() {
    
         if (isset($_SERVER['HTTPS']) &&
            ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
            isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
            $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            $protocol = 'https://';
            }
            else {
            $protocol = 'https://';
        }
    
        $currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        $currenturl_relative = strtolower(wp_make_link_relative($currenturl));  
            //echo $currenturl_relative;
    
        switch ($currenturl_relative) {
    			
    		case 'expensereport':
    		    $urlto = 'outside_url';
    		    break;
    
    		case 'mulch':
    		    $urlto = 'outside_url';
        		break;			
            default:
                return;
        
        }
        
        if ($currenturl != $urlto)
            exit( wp_redirect( $urlto ) );
    
    }
    add_action( 'template_redirect', 'redirect_page' );
    

    *************************

    However, this does not work for /mulch because somehow something overriding this function.

    @sterndata Do you think preventing WP to guess URL will be the solution?
    Or this is something different?

    TIA!

    Thread Starter home2mars

    (@home2mars)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding random word to the end of homepage url’ is closed to new replies.