Category Archives: Wordpress

Does Bluehost Suck

Does Bluehost Suck?

As a web hosting company, many have expressed the opinion that Bluehost stinks:

I signed up for Bluehost 2½ years ago for a 3 year subscription at the rock bottom price of about $3.00 per month, paid in advance. I suspect they pack their servers with hundreds of websites and mine can really slow to a crawl. But, for someone who wants to learn about web development and has no plans to make money at it, the price cannot be beat.

I rarely need any support from Bluehost, but my site was recently hit by a malware attack. I now have something to say on the subject of: Does Bluehost suck?

Continue reading

Enqueue Scripts with ‘defer’ or ‘async’ attribute

First, add a filter for the script loader tag:

add_filter( 'script_loader_tag', array( $this, 'add_defer_attr' ), 10, 2 );

Then, enqueue the script, noting its WordPress handle (in this case ‘hotMessScripts’):

 plugin_dir_url( __FILE__ ) . 'js/hotMessAdmin.js', 
 array('jquery', 'jquery-ui-sortable', 'jquery-ui-dialog')

Then, identifying the script’s handle, alter the script’s tag by inserting the desired ‘defer’ or ‘async’ attribute before the ‘src’ attribute:

/* Add defer attribute to hotMessAdmin.js script tag */
public function add_defer_attr( $tag, $handle ){
	if( $handle == 'hotMessScripts' ){
		return str_replace( ' src', ' defer="defer" src', $tag );
	} else {
		return $tag;

Remember, all script tags will run through this filter. The unaltered tag must still be returned even for the scripts tags that should not be changed, thus the else clause is important.

Posted: Wednesday, January 9th, 2019
Category: Wordpress

Enqueue Javascript in WordPress: What I wish someone told me

I wanted some javascript on the front page to display a button that toggled the visibility of a doodle at the bottom of the screen. In a normal website, the necessary javascript is written in a separate file which is then called with <script> tags in the head of the html file. How do you get these <script> tags into the head of a WordPress page?

The Codex and user forums tell us that hacking the header template with <script> tags is a bad thing. WordPress has its own method, called enqueuing, for adding javascript. I pulled my hair out reading the Codex and many tutorials to learn how to get this done. It confused me for a long time. Here is what would have made it much easier for me.

The two things you need to know to properly enqueue javascript in WordPress are:

  1. The function wp_enqueue_script; and
  2. The hook wp_enqueue_scripts

Once I realized that these nearly identical looking things are completely different, it all fell into place.

Here is how both of these fit in my child theme’s function.php file to make it all work.

Line 6 defines the grp_include_scripts function. The sole purpose of this function is to invoke the wp_enqueue_script function which tells WordPress:

  1. to refer to the script by the name “front_page_script”;
  2. the address where the script file is located; and
  3. that the script needs jQuery to run (JQuery is a dependency).

The wp_enqueue_script function says to WordPress, “when it comes time to include script tags in the head of the page being loaded, please add one for my script too. Here is what you need to know about it.”

Like any other php function, grp_include_script() will not execute until called by some other code. That’s where line 12 comes in. The add_action function tells WordPress that you want to do something when it comes to a particular point in its operation. The wp_enqueue_scripts hook is at the point where WordPress determines what scripts need to be loaded with the page being loaded. In line 12, the add_action function tells WordPress, “whenever you reach the wp_enqueue_scripts hook, please run the grp_include_scripts function (line 6) to see what scripts I might have for you.”

And that’s how scripts can be included using function.php without ever touching a template.

Note that I wanted to run this particular script only on the home page, so I used the “if” statement on line 7. Just take out this conditional for scripts that should be loaded on every page.

Posted: Thursday, July 24th, 2014
Category: Wordpress

Development of Legal Research Page

For the Legal Research page, created a custom page template (legalResearch.php) based on the default page template. I wanted this page to be full width. Although get_sidebar is removed from legalResearch.php, the main content does not fill the entire screen width by default. Without more, a blank space is left where the side bar would be.

For the main content area to extend the full length of the screen, the <body> tag must have the “full-width” class. Wrote a custom function in the template to filter the body_classes() function to add the “full-width” class when using the legalResearch.php template. See the “Add Classes By Filters” section of the body_class() reference.

I wanted to append other content to the page, depending on which section the user clicked in the summary table. The template contains a filter to do that. For this to work, the appended content must be a child of the page and the id of the page must be posted via GET:

if the id is not a child page, nothing will be appended. Passing id=shebang will append all of the child pages in the menu order.

Finally, I replaced the table for the top grid to divs. The problem is that floated divs do not have the same height as its neighbor in the same row. The solution is to use display:table and display:table-cell as described in this nice post. This change was essential for maintaining a responsive web design.

Moving WordPress Site to New Domain

Having now moved several WordPress sites from their test environments to new domains, I found the official instructions for moving a WordPress site to be confusing. Here are the steps I follow:

  1. Export the old database to SQL file.
  2. Run the SQL file through this online search and replace utility. This will update all the links, including the media files, to the new domain.
  3. Create a new empty database for the new domain.
  4. Move the entire WordPress directory to the new host.
  5. Update the wp-config.php file with the information needed to access the new database.
  6. Update the permalinks to the default and press save. Then return the permalinks to the way you want them.

That should do it.

Posted: Sunday, July 20th, 2014
Category: Wordpress