Migrating WordPress Multisite from Media Temple to SiteGround

Posted on

A few years ago, I wrote about domain mapping using WordPress Multisite on Media Temple. This year, I’ve been consolidating all of my hosted websites to a single SiteGround account and the very Multisite instance I wrote about needed to be moved over. I had been avoiding it but the time had come, especially since I was getting knocked for $50/month just for those sites. Here’s how I did it.
Continue reading “Migrating WordPress Multisite from Media Temple to SiteGround”

Deleting 3 Million Spam Comments from a WordPress Database

Posted on

Over at the Crowd Favorite blog, I wrote up a post about an interesting problem I solved recently. I laid out everything you need to know there, but it involves downloading a HUGE database and putting WP-CLI to good use. If you haven’t used it before and you do development with WordPress, it’s super valuable. Anyway, check out the post – it’s a good one!

Deleting 3 Million Spam Comments from Your WordPress Database

How to Build Better Web Pages in WordPress

Posted on

When I was creating the website for my new project WP in One Month, I wanted to make sure the home page was diverse with content, different sections, and a lot of information. As a WordPress developer, I could have built a completely custom page template with custom fields for each section, and I could have made use of one of the many plugins to do that. However, I also wanted to get the site up and running quickly. I was pivoting the business and wanted to focus more on executing ideas than on developing the website (I know many developers can relate to me here). I opted instead to build a simple child theme from the theme Ward and use a page building plugin called Beaver Builder. It saved me literally hours of development and gives me lots of flexibility.

Continue reading “How to Build Better Web Pages in WordPress”

WordPress Database Encoding & the Case of Disappearing Widgets

Posted on

Recently I was updating the widgets on my homepage to promote the new WP in One Month. I decided to do so with the logo and a caption, making Jetpack’s Image Widget the perfect candidate. I uploaded the logo, added a title, then copy and pasted the text from the website’s ‘Jumbotron’ area for the caption. I clicked ‘Save’ and something strange happened: all of the Image Widgets, everywhere on my site, disappeared. I tried to do the same thing with a Text Widget, thinking maybe there’s a bug in Jetpack’s Image Widget or it doesn’t allow certain text/markup. After going through the same steps and clicking ‘Save’ every Text Widget on the site disappeared. I decided (really, was forced) to do some investigating.

Continue reading “WordPress Database Encoding & the Case of Disappearing Widgets”

Draw Cherries using HTML5 Canvas

Posted on

I’m teaching a class on 2D Animation this semester and opted to use web technologies such as HTML5 Canvas, CSS Transitions, and Javascript. In this tutorial we are going to use the canvas element to draw 2 cherries with stems. I’m having my class use CodePen for their assignments, so this tutorial kind of assumes that. If you want to see the final product, head on over here.
Continue reading “Draw Cherries using HTML5 Canvas”

Adding the Media Uploader in WordPress

Posted on

…without including the Editor. In the Admin. That was a really long title, so I hope you don’t feel mislead! I was recently working on a project that required a Custom Post Type without the editor, but needed the Media Uploader.

Note: This is not a full-blown tutorial. The purpose of this post is to help those troubleshoot the fact that the media uploader is not working, given the conditions above. 

Here is how I define the media custom meta box (this is only part of a bigger array of arguments):

array(
    'title' => __( 'Upload File', 'jlc' ),
    'type' => array( 'custom-post-type' ),
    'id' => 'upload-file',
    'items' => array(
        array(
            'type' => 'media',
            'name' => '_upload_file',
            'label' => __( 'Upload File', 'jlc' ),
            'label_position' => 'before',
        ),
    ),
),

In the post type definition, here’s what the ‘supports’ argument looks like:

'supports' => array(
    'title',
    'page-attributes',
    )

Note that the editor is not listed. If it were, the media uploader scripts would be automatically added. Instead, you get an error that wp.media is undefined. Luckily, there’s an easy fix for this. Simply add this line in where you custom post type is defined:

add_action( 'admin_init', 'wp_enqueue_media' );

This says that when you are on the admin, add the required media scripts. That way, even if the editor isn’t loaded, the media uploader will be.

Quick Tip: Use Post or Page Slug as CSS Class in WordPress

Posted on

I don’t know why, but for some reason, I thought WordPress already included the slug of a post or page in either the function body_class() or post_class(). Doing some work over this weekend I realized that’s not the case, but luckily, it’s very easy to do.

The functions body_class() and post_class() serve as a way for you to easily customize a page’s CSS based on attributes of the page being viewed. They will output things like the post ID, the custom post type, if the page is the blog, home, or front page, and more. One thing it does not include, however, is the post slug. This could be useful if you want to style each of your posts a certain way, or in a more likely scenario, style each page a certain way. If you want to do this, the code is fairly straight forward; both functions accept an option argument: a string of your own classes. We use that combine with the $post array, like so:

<?php body_class($post->post_name); ?>

or, if you want to do it on a post-by-post basis:

<?php post_class($post->post_name); ?>

Note the latter must be used inside the Loop. Using this, if you have a page named, “Services” with the slug services, the output would look something like this:

<body class="page page-id-108 page-parent page-template-default services">

Now you can use the .services (or whatever) class name to do some custom stuff instead of needing to know the page or post ID.