As I’ve been working to update our instances of WordPress to the new theme, I’ve learned a few things. I thought I’d take a minute to document them for myself (and anyone else who cares to read).
Source Code for a Page
Viewing the source code for a page can be helpful when troubleshooting problems on a page. Typically I use the Chrome inspector to see the underlying HTML/CSS and resolve an issue. In this case, however, I was trying to compare a page in our production and development environments. I pulled up the source for both pages and did a diff on them using Notepad++. The files were identical. But when I looked at the pages in the Chrome inspector, there were clear differences. Ultimately, I discovered that viewing the source only shows what the server sent at the time the browser requested the particular webpage. This does not include changes made on the client by JavaScript.
WP URL Autocomplete
I also learned that WordPress will autocomplete URLs for you. For example, this post is located at https://pages.charlotte.edu/forsyth/blog/2018/03/09/tips-and-tricks/, but if you only input https://pages.charlotte.edu/forsyth/blog/2018/03/09/tips into the address bar, WordPress will still navigate to this post. In WordPress this is called canonical redirect.
WP Menus
WordPress allows users to automatically add new top-level pages to a WordPress menu. You can select this option by checking the box below your menu.
However, subpages – pages you create with a parent using the page hierarchy – don’t get added automatically. I’m not sure why WordPress has not implemented this as it seems intuitive to me. In fact, if you do not create a menu and your theme allows a fallback, then WordPress will create a menu including subpages, using a function called wp_list_pages. Having a fallback menu complicates things in it’s own way. For example, if you do not want a menu, you have to create a menu with no menu items. Very counter-intuitive. I’ve done a couple of things to try to “fix” this. First, since our theme previously used a fallback, many sites were relying on that fallback. I wrote a script to create menus for those sites, which mirrored the menu they had previously. The new menu, called Page Hierarchy Menu, automatically adds new top-level pages. Then I added a plugin called Auto Submenu to take care of any subpages.