Ok, so I have a wordpress site with a lot of pages and menus that I’ve defined in the appearance/menus section of wordpress.
One of my pages has a little payment form on, which I’d like to link to with https://blahlbah.com/thepage.. and for all the other pages I’d like them to remain as http.
Even if I set an absolute link to the https page all the other pages being relative links become https also after you visit that page.
Is there a plugin or a hack or something to just specify that one page as https?
Cheers,
John.
You will need to convert the relative links to absolute links. You can do this in the
wp_nav_menu_objects
filter, which gets all menu items. Just edit theurl
property of each item.Another option would be to extend the default
Walker_Nav_Menu
with one that overridesstart_el()
, so you can modify the passed$item
there before you pass it to the parentstart_el()
.These are relative links you added yourself? If you add a link to a WordPress Page or Post via the menu editor it should be absolute by default.
I like Jan’s first idea–filtering wp_nav_menu_options. Could be a good all-around solution, and could be quickly turned into a plugin. Maybe even add a checkbox to the edit screen saying “serve this page over SSL” or something?
In the past, I’ve used a hacky redirect solution with htaccess. It looks something like:
This works well (and is very easy to implement) if you’re only worried about one page, but gets to be a real pain if you have a bunch of HTTPS URIs, or if you’re not good at troubleshooting rewrite rules 🙂
Here is some code to force SSL on non-ssl pages:
Basically, you can use this code to force ssl on your desired page(s) and do the opposite to remove ssl for all other pages. You may, in this case, want to specify the second parameter for wp_redirect to enable a 301 redirect rather than a 302. You will also want to ensure as best you can that all links point to the https version.