WordPress jQuery widget added callback

Jan.12.2015 | 08:51 pm

So, I keep expanding my bag of tricks for WordPress, and one of the tricks I have is a media uploader that be placed in a meta box or in widget settings by just adding a couple lines of HTML, jQuery does the rest from there. The problem I ran into was when a new widget was added the click events were not bound to them, which is because the html for the widget is dynamically added, but you already knew that.

I dug into the WordPress jQuery code (/wp-admin/js/widgets.js to be exact) and found this:

This will allow you target the newly created widget with a function you've created:

Full post »

Adding CSS classes to a WordPress Widget

Jan.08.2015 | 01:57 pm

Let me preface this, this is only if you are creating a widget and not if you just want to add a class to an existing widget, there are plugins that do that.

It's really actually simple, I just could not find the answer right away because it isn't one of those things mentioned in the Widgets API section of the WordPress Codex.

The above link has this in the Example when creating a widget:

If there were one more line (like the below), then this post wouldn't exist. The array that...

Full post »

Auto resize WordPress editor after unhiding it

Oct.15.2014 | 11:50 am

The project I am working on has several templates, some which do not use the main WordPress editor. For those templates, I typically hide the editor via jQuery's .hide() or .slideUp methods.

The problem I ran into was that when editing a page using a template that did not use the editor, then switching the template to one that used the editor, the editor would be broken until the user scrolled, resized the window, etc. This is due to how WordPress 4.0 now resizes the editor window automatically to fit the content in it.

The trick to fix this is to turn the auto resizing off and on again, which fires off all of the auto resize functions. The methods are:
<...

Full post »

Getting a WordPress page by its template

Oct.13.2014 | 01:11 pm

When I create a WordPress theme, I like to make things dynamic, clean and easy for the user(s) of the theme. Today I came across an issue where I needed to be able to link back from a single custom post type to the page that is using the template that displays the listing of the custom post type. The page with the template is currently named 'Portfolio' and it displays all of the 'Galleries', the link will take the visitor back to the 'Portfolio' from a 'Gallery'...exciting!

I could use get_permalink( ID ) to get the permalink by the ID, or get_page_by_path( 'Portfolio' ) to get the page (and then its ID) by its name; but what if the user decides to use a differe...

Full post »

Unstrapping the Boot

Oct.09.2014 | 10:22 am

Coffee is made and knuckles are cracked, I believe it is time for a update to this design. I probably won't change much visually, but a lot of the back end needs to change. This theme was one of my first ventures into responsive design and Bootstrap, and now I know a few more tricks up my sleeve...and some down time.

Full post »