Custom CSS/JS Plugin for WordPress

We’ve recently released a simple and easy-to-use plugin for WordPress that allows you to easily add custom CSS (styles) and Javascripts in your pages and posts as well as on a global (sitewide) basis.

Our Custom CSS/JS plugin for WordPress means you don’t have to modify or override templates in your theme any longer.  Now you can easily add overriding styles, new styles, and custom Javascript in any page or post or in the entire site.

It’s pretty easy to use.  Just download and copy it to your plugins directory, then activate it through the admin and you’re ready to go!

Integrating WordPress Into CodeIgniter

One of the sites I maintain was built using CodeIgniter.  If you don’t know CodeIgniter and you are a PHP developer, definitely check it out.  It is a lightweight, extensible framework (don’t they all claim that?).  It does not have an ORM (Object Relational Mapper) but you can easily integrate your favorite (Doctrine, for example.)

I have been building website in CodeIgniter for a while, however this one site is growing beyond scope (again…don’t they all?) and now is requiring more dynamic content.  It’s not quite to the phase where I would rebuild it using WordPress and in any event I don’t really have the motivation to build a custom theme to keep the same look and feel.

So, I’ll be using the tried and true methodology of integrating the “guts” of WordPress so that we can update pages and posts without having to do a major rewrite of the site.

To get started, I downloaded the latest version of WordPress (3.9.2 at the time of this writing) and installed it in a web-accessible sub-directory called “blog.”  I had read a few places online where people had some problems with the conflicting routing systems of WordPress and Codeigniter and went so far as to change the core code in CI and/or WordPress, but I found a much simpler method:  simply update the rewrite rule in your Apache config file:

RewriteEngine on
RewriteCond $1 !^(index\.php|blog|images|robots\.txt|css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]

The second line lists “pass-through” exclusions that are not routed via the index.php file and routing table for Codeigniter.  Now I can access WordPress directly and run the setup and enter and manage content.  The next step is to create/modify model files in Codeigniter to access WordPress instead of the original database.

I had a model call ‘Events’ that was used to obviously store upcoming events and seminars for this client.  I’m going to switch it to use WordPress to pull posts instead.

function getEvents($numPosts = 3) {
  $args = array( 
    'numberposts' => $numPosts, 
    'order_by' => 'date', 
    'category_name' => 'events' 
  $myposts = get_posts( $args );
  return self::fillEvents($myposts);

The method “getEvents” formerly used the Codeigniter ActiveRecord system to query the db and was updated to use WordPress methods. As you can see, it uses the “get_posts” method to pull the last N posts from the Events category (with the slug “events.”)  The “fillEvents” method iterates through the records and returns an associative array.

private function fillEvent($post) {
    $event = false;
    $date = strtotime(Date("Y-m-d H:i:s"));
    $custom = get_post_custom($post->ID);
    if (isset($custom['start_date'])) {
      if (strtotime($custom['start_date'][0]) > $date) {
        $event = array(
          'id' => $post->ID,
          'title' => get_the_title(),
          'date' => get_the_date(),
          'start_date' => $custom['start_date'][0],
          'end_date' => $custom['end_date'][0],
          'location' => $custom['location'][0],
          'excerpt' => get_the_excerpt(),
          'content' => get_the_content(),
          'link' => get_the_permalink());
    return $event;

 private function fillEvents($posts) {
    global $post;
    $events = array();
    foreach( $posts as $post ) {
      $event = self::fillEvent($post);
      if ($event) {
        $events[] = $event;
    return $events;

At this point I should note a couple of things:

  1. I do not use the templating system built-in to Codeigniter.  I replace it with Smarty as I believe it is a more extensible and versatile system.  Plus, I can upgrade the Smarty implementation without having to update Codeigniter.
  2. I usually return my data objects as associative arrays that are passed to my display templates.

The end result is that I do not have to change my controllers or my template (.tpl) files from their original design.  I just made sure that my model returned the same data in the same format 🙂

So far I have not run into any problems regarding routing or cookies, and my next step is to leverage the WordPress User system to create user accounts.  I’ll be sure to update this post (or create a new one) if I find anything.

Remote Post Publisher

I’ve been using WordPress for a while, and one of the things that it lacks to be further forced into a role of a CMS is the ability to remotely publish content from one server to another.  There is an import/export function that works to some degree, but it does not allow for a quick, one-click method to publish a post or page to another server.

Introducing WordPress Post Publisher v1.0 (beta)!

WordPress Post Publisher (WPP for short) allows you to quickly and easily publish content (including media) from a local or staging server to a remote/production server without having to copy your database from one environment to another!

This plugin is in the final stages of cleanup and testing and is set to be released within the next 30 days.

Currently multi-site is not supported and only posts, custom post types and pages are supported.

My plan is to include support for multi-site shortly after release.