Software Engineering in WordPress, PHP, and Backend Development

Tag: JavaScript (Page 7 of 12)

Articles, tips, and resources for JavaScript-based development.

Quick Tip: Multiple InfoWindows with Google Maps

Recently, I’ve been working with the Google Maps API in order to plot locations that are stored as custom post type meta data in the WordPress database.

Google Maps InfoWindow

 

The general functionality is as follows:

  • For each of the locations stored in the database
  • Generate a pin for the location
  • In addition to creating a pin, create an information window that shows the pin’s location

The information windows that sit above the flags are also called infowindow within the context of the API.

The Google Maps API documentation is pretty good in covering stuff like this, but I did run into a couple of gotchas when working with it, so I thought I’d document them here just in case anyone runs into the same problem.

Continue reading

Using jQuery To Set Select2 Selected Value

As much as I firmly believe in making sure that anything we build for WordPress especially as it relates to the dashboard should remain as consistent as possible.

As with anything, there are a few exceptions that I’ve made in the work specifically when it revolves around large select elements (multiselect or no).  That is, I’m a big fan of Select2 – I’ve written about it a couple of times and how I’ve used it in a couple of projects.

Because this is something that I regularly use, and because I know a number of WordPress developers (and general web developers, as well) also use this in their work – both in the dashboard functionality and in the public-facing functionality, as well – I wanted to share one way in which I’ve needed to programmatically set an option.

Continue reading

Making Anonymous Functions Maintainable

Obviously, the majority of the content that I write for the site deals with WordPress in someway, but there are times where I talk a bit about JavaScript, related libraries, and so on.

The Face of Anonymous Functions

The Face of Anonymous Functions

Generally speaking, a lot of the JavaScript that’s written in the context of WordPress is done using jQuery because it’s the library that ships with the core applications, it’s tried and true, and its a good fit for a lot of the DOM manipulation that happens in themes and in plugins.

But one of the things that I’ve begun to notice over the past few years is that writing maintainable JavaScript (using jQuery or not) gets a bit more difficult when using anonymous functions.

Continue reading

Two Solutions for “JavaScript Reference Error Is Not Defined”

If you’re working on any type of web site or web application that has any other dependencies either for its front-end framework – such as Bootstrap and Foundation – or from the site’s foundation – such as Rails or WordPress – there’s a chance that your own JavaScript sources may result in the following:

Reference Error [variable] is not defined.

In some cases, this can be simply referring to a variable that isn’t defined (perhaps the most popular is when jQuery’s $ function has been dereferenced and you’re trying to use $) and simply needs a definition.

But, in other cases, there are times where it may not be as simple.

Continue reading

An Example of How To Remove Empty HTML Tags

One of the most tedious aspects of building WordPress themes is customizing and styling the comments template. This includes not only the comment form and the pingbacks, but the response text, as well.

Don’t get me wrong: It could be worse, and after you’ve done it a few times, it’s likely that you’re going to use many of the same strategies that you’ve used in previous themes or templates.

But there are examples in which certain elements will render as empty HTML tags. If you have given those tags a specific, say, background style then it can really create somewhat of an ugly experience for your readers.

The challenge, then, comes at being able to remove empty elements before the user can see them. But there’s a catch: It can’t be done on the server side because the server side sees the HTML as you would expect it to be rendered whereas the browsers take the liberty of parsing the document and adjusting the markup so that it’s a bit more semantic.

At least that’s what most of them try to do.

Anyway, this can cause some unintended side-effects.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑