WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Pages and Slugs (5 posts)

  1. onmiddleground
    Member
    Posted 1 year ago #

    Hello,

    I don't really like asking what appears an obvious question, but when I create a custom page (say its called subscribe) and I create a page in my theme folder called page-subscribe.php, how can I link to that page without creating a page/slug in the admin site called subscribe? My PHP file contains a bunch of code and I really don't want someone to be able to see the page name/slug in the pages listing?

    Thanks,
    Gary

  2. kjodle
    Member
    Posted 1 year ago #

    All PHP files contain "a bunch of code" but that code generates HTML, so users will not be able to see the actual code.

    I'm not sure that is your issue, however. Do you mean that you don't want people to see the page name in the URL?

    I have no idea what you mean by this:

    link to that page without creating a page/slug in the admin site called subscribe

    because pages and slugs are two different things.

    It might be more helpful if you explained why you don't want someone to see the page name or slug "in the pages listing" (there are multiple things this could refer to, so again I'm at a loss here). There may be a simpler, more direct way to achieve that than by what you are describing here.

    You have piqued my curiosity.

  3. onmiddleground
    Member
    Posted 1 year ago #

    Let me try to explain it again. Assume I want to link to a page called subscribe. My link may be something like http://localhost/subscribe where subscribe is the slug name. In order to view the contents of subscribe from a browser, I typically have to create a page in the admin site with a slug called subscribe. So that is all good.

    Now assume I want to have the subscribe page contain custom PHP code (doesn't matter what is in it) so I create a page in the root theme folder called page-subscribe.php and that works just fine as well. However, what I want to know is why did I have to create the page/slug in the admin site in the first place in order to have a valid slug name? Instead I just wanted to create the page in the theme folder called page-subscribe.php so I can still link to it but bypass the need to create the page in the admin site.

    Does that help clarify?

  4. kjodle
    Member
    Posted 1 year ago #

    why did I have to create the page/slug in the admin site in the first place in order to have a valid slug name?

    IIRC, slugs exist so your permalinks structure knows what to call it. Pages and posts don't exist as separate pages; rather, they are generated on the fly by WordPress using data pulled from the MySQL database. Doing what you're describing really won't work, because http://example.com/subscribe will automatically link to the page you created from within WordPress, rather than the page you coded by hand.

    What you want is possible, but it will take some work in htaccess, assuming your host is running Apache.

  5. onmiddleground
    Member
    Posted 1 year ago #

    Thanks for responding. This is what I assumed but just wanted confirmation.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags