August 30, 2019

H Tags and Auto-Constructing an Anchor Index

Origin Story I got a fairly dense Word document that needed to go online in way that people could more easily navigate. After checking it out, it appeared we had a large number of sections but we were lucky in that they were designated by H tags of various levels. Now I could have gone through and added IDs to each H tag by hand but my masochism doesn’t run that way. The challenge was now to see if we couldn’t do this automatically with javascript. Build It It ended up being more succinct than anticipated and will undoubtedly be used again in other scenarios. I commented it up below to explain things. The other thing to consider is that maybe you can’t use javascript on the site. That’s ok, run it like this and then inspect element and copy the results. Now you can paste that into any place that takes HTML and you’re good to go. See the Pen health hub index by Tom (@twwoodward) on CodePen.

Logging in PHP

In javascript, figuring things out is not to bad. For almost everything, I can just use console.log(whatever) and spit out the data I’m trying to figure out right there in the browser. With PHP is more difficult. You can var_dump() many things. You can improve on that using print_r to make those gnarly1 objects and nested arrays legible. But for the longest time, I had no good path for logging the information that happens in function that weren’t visible anywhere. I resorted at one point to writing the data using insert_post. Look at the madness below. Then, just the other morning, I was feeling particularly unhappy with this pattern and happened upon this post. This little snippet is now my best friend.2 I can staple that to the bottom of plugins/themes in development and then use write_log() in any number of useful ways. The author mentions using write_log( __LINE__ ); to log if the line in a particular place is every reached and there are many other ways you can tweak this to do what you need. It’s just so nice now to be able to consistently log data from anything in PHP land to a designation location. It is times like this that I feel bolstered in my opinion that I don’t know anything about programming. It’s also that […]

Badge of Badges Collage

I’m not a huge badge fan, even though I see the potential. I’ve used Mozilla’s Open Badges over the years to gather together different online badges that either I have earned or created (mostly via CLMOOC but also, in the early days of Thimble and Web Maker, etc.). This week, I received a notice that […]