Posted by & filed under WordPress.

Love the MathJax plugin for WordPress. Makes it really easy to insert equations, assuming you’re somewhat familiar with Latex formatting.

Problem is, there is always no space below the equation. I’ve been just hitting enter a couple of times after the closing latex tag, but I wanted a better solution.

Since there’s a syntax attribute as part of the latex tag, I decided to add my own. If I set syntax to block, the plugin now wraps the equation in a div that has a bottom margin of 32px.

function latex_shortcode($atts,$content)  {
	self::$add_script = true;
	//this gives us an optional "syntax" attribute, which defaults to "inline", but can also be "display"
				'syntax' => get_option('latex_syntax'),
			), $atts));
	if ($syntax == 'inline') {
		return "\(" . $content . "\)";
	else if ($syntax == 'block') {
		return "<div style=\"margin-bottom:32px;\">\(" . $content . "\)</div>";
	else if ($syntax == 'display') {
		return "<div style=\"margin-bottom:32px;\">\[" . $content . "\]</div>";

I changed the latex_shortcode function a bit. Added another check for $syntax == ‘block’, and if true then wrap the output in a div. Also use the same div settings for the display syntax, although I don’t really like the display syntax because it centers the equation.

Posted by & filed under WordPress.

Came across an issue where the TinyMCE editor inside WordPress was stripping out <textarea> tags as I switched between the HTML and Visual editors, and the page I was working on needed a textarea.

After digging through Google I came across a pretty good reason. A textarea inside another textarea can cause problems so they’re not allowed. Makes sense, but not really a solution.

What I did was add a bit of code to my theme functions.php file to create a pseudo shortcode.

function allow_textareas($content) {
	return preg_replace(

It’s not really a true short code, but it does work. And I didn’t want to do an actual short code because I would have to worry about the different possible attributes. Regex allowed me to just replace what I needed to and leave the rest.

Now all I have to do is [textarea][/textarea] and the function takes care of replacing it with the right HTML tags.

Posted by & filed under WordPress.

Screen shot of the plain text post list page.

Just uploaded a plugin to the WordPress SVN that creates a plain text custom post type. It’s a post that has absolutely no formatting, and even strips out the WordPress theme leaving just the text.

What’s the point?

I’m playing around with a network installation of WordPress. One of the sites that I’m moving to the network was originally a Dreamweaver site and needs a JavaScript file that’s specific to that site. But one of the advantages of moving this site to a WP network is that I don’t have to do as much individually to an specific site so I didn’t want to have to customize a theme for a single site. With this plugin I’m able to create a post that contains the contents of the external JavaScript file, I don’t have to touch the theme files or, and any customization of that file doesn’t affect any of the other sites on the network.

How’s it work?

Plain Text Files added under the Pages tab

After activating the plugin a new menu item is added under the Pages tab. Adding a new Plain Text File post works just like any other post except there are fewer meta boxes on the page and Tiny MCE is disabled.

The other thing you might notice is that the tab key doesn’t work like it’s supposed to when typing in the text area. Instead of moving on to the next field like is normal for a web page, the tab key works like it does in a normal text editor.

Two new fields are added to the post meta box just above the Publish button.

The first allows you to pick what type of file you’re editing; CSS, JavaScript, or plain text. This affects the Content-type header that is sent with your file. A CSS files gets text/css, JavaScript gets text/javascript, and plain text gets text/plain. For most browsers this won’t matter, but it’s done anyway.

Publish meta box for the plain text custom post type

Where it does matter is if you check the box to auto load your file. This will add a link to your plain text post into the head section of your theme. So if you create a JavaScript file and select automatic linking, WordPress will put a link to the post including the <script> tags. Same with CSS.

A plain text file will not link even if you check the box. Linking to a non-CSS, non-JavaScript file doesn’t make sense in the header.

Need a demo?

Not much to see since it’s just linking to an external JavaScript file, but the site I wrote this for is


You can download Plain Text Custom Post Type from the WordPress plugin library or through WordPress.

Posted by & filed under WordPress.

Had some free time this week and kicked out a couple new WordPress plugins for another site I’m working on.

Plain Text Custom Post Type adds a new custom post type to WordPress that outputs as just plain text.

What it was written for, and what I’m using it for, is to allow me to edit a JavaScript file from within WordPress. The site it’s written for is a WordPress network site and I didn’t want to have to worry about customizing a theme for just one blog or uploading through FTP.

You also have the option of automatically linking the files in the head section of your theme if it’s a JavaScript or CSS file.

The other plugin is called Insert JavaScript and CSS. Similar to the other, but this one lets you put attach JavaScript or CSS to a post or page. Written for the same site as the other, there were pages that I needed to attach a bit of JavaScript to easily and none of the existing plugins I tried would do exactly what I wanted without a lot of overhead.

When I get a chance I’ll put up a more detailed post on both of these, but if you follow the links above you can go to the WordPress plugin site and download from there.

Posted by & filed under WordPress.

Just finished up a WordPress plugin that allows for arbitrary JavaScript and CSS to be included in the head section of posts.

I needed to come up with some small project to put together and I needed this for a larger scale project I’m planning, so it was a good fit.

For now though, I’m waiting on acceptance into the WP plugin library. When that happens I’ll post again. In the meantime, here are some screen shots to review. –Ryan

Icon added into the media area.

Screen where you can enter JavaScript. Tabs on the same page allow for CSS and display a bit of help.


Posted by & filed under WordPress.

Been working on a project for the past couple of days, and spent a bit of time this morning trying to get WordPress to do something. As usual, WordPress came through. Just took me knowing what to enter.

What I’m working on is a plugin that adds to the <head> section of a page based on meta_key values in the posts. There are two potential keys, and if either one or both have content I need to act.

To start, I used the meta_query field in the query_posts function. Worked like a charm, but would only find if one of the two meta keys wasn’t blank. Dug a bit into meta.php and found what I was after.

$myPosts = query_posts(array(
    'meta_query' => array(
        'relation' => 'OR',
            'key' => 'field_1',
            'value' => '',
            'compare' => '!='
            'key' => 'field_2',
            'value' => '',
            'compare' => '!='

That was it. Just added relation=’OR’ to the argument array and now it finds all posts that have a value in either one of those meta keys.

Posted by & filed under Tweets.

  • @conservativeact is the worst kind of spammer. Emails that prey on your fear to get you to give them money to fax congress. #
  • Hey @comcast I shouldn't have to jump thru hoops to report spam on your network. Should be able to fwd to abuse & you take it from there. #