• What I want to do: put a link on my WP site like https://domain.com/sports. When the user clicks on it, a custom function runs that generates a chunk of HTML and puts it up on a properly-themed page. This can’t be *that* hard, but I’m enough of a WP newbie that I can’t figure out how to do it. Any advice out there? Thanks!

    • This topic was modified 3 years, 8 months ago by jrmatwpress.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Is the “random-path” actually random? Or you want it the same path with different results every time?
    For a known path like your example, you can create a page with that slug and assign it a page template with your custom function. Or make it into a shortcode via a plugin, so it is not dependent on the theme.
    You can do this with unknown slugs, but you need a known base if you don’t want to have much in the URL.
    Or you can try to hook into the 404 processing, but it’s tricky since WP clears out a bunch of the request once it is determined to be 404.

    Or you can make a plugin that determines if the URL is one of these requests, without it being tied to a page, but you would have to put something identifiable in the URL (or you just get a lot of 404s).

    Thread Starter jrmatwpress

    (@jrmatwpress)

    That helps a lot; thanks! FWIW, I’d be happy to be able to handle a few defined paths without any additional arguments being passed in, but I might graduate to the latter once I’ve got the basics working.

    This is one of those places where Drupal and WP see the world differently, and I’m trying to get my head wrapped around it. Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get domain.com/some-random-path to run a bit of code and display the resu’ is closed to new replies.