Enabling mod_headers and CORS with Apache2

I’ve been working on a project and wanted to test out accessing media from a different domain using CORS. There’s two steps to this. Make sure you have Apache mod_headers enabled. Use apachectl -M on the command line interface and review the results. It should include something like this: headers_module (shared). If not then run … Continued

Run Shortcode in WordPress Excerpts

Add this to your functions.php or your plugin.

add_filter( 'get_the_excerpt', 'shortcode_unautop');
add_filter( 'get_the_excerpt', 'do_shortcode');
add_filter( 'get_the_excerpt', 'do_shortcode', 5 );

Moving a site from Drupal to WordPress

Moving a site from Drupal to WordPress

Exporting from Drupal Use Views Data Export module and these instructions. When exporting tags there’s a couple options. 1. You can have all the added tags in one field value. 2. You can export each taxonomy individually. Depending on how you want the tags within the WP site you may prefer one way or another. … Continued

Programmatically Flush WordPress Permalink Rewrite Rules

When adding rewrite rules with add_rewrite_rule add this to the file you are editing and avoid clicking save on the permalink settings page. // do not use on live/production servers add_action( 'init','maybe_rewrite_rules' ); function maybe_rewrite_rules() { $ver = filemtime( __FILE__ ); // Get the file time for this file as the version number $defaults = … Continued

WordPress Admin Taxonomy Sidebar Resize

I’m currently setting up an admin for a clients redesign. There’s going to be a hefty amount of categories and I wanted to make the selector in the sidebar resizable for at least a little bit easier viewing.

The simple if not completely cross browser friendly (chrome, ff, safari) way to do this is css’s resize.

/* #talent-categoriesdiv is the .postbox the parent box */
.wp-admin #talent-categoriesdiv .inside{
    /*set an initial height, otherwise it will expand to show all rows*/
    height: 300px;
    resize: vertical;
    overflow: scroll;
}

.wp-admin #talent-categoriesdiv .categorydiv{
    height: 100%
}

.wp-admin #talent-categoriesdiv .tabs-panel{
    height: calc( 100% - 78px );
    max-height: unset;
}

Add Special Chars to WordPress TinyMCE Char Map

Had an issue where a clients blog post had one of these in the post and it wasn’t being displayed right. The real issue was changing the ‘post_content’ field of the wp_posts table to UTF-8 Unicode (utf8mb4) from cp1252 West European, but (!) along the way I tried this. Put this in a plugin or functions.php and … Continued

Add browser and device name to WordPress body class

Github Gist

<?php
// Add Browser-Detection
function mv_browser_body_class($classes) {
    global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
    
    if($is_lynx) $classes[] = 'lynx';
    elseif($is_gecko) $classes[] = 'gecko';
    elseif($is_opera) $classes[] = 'opera';
    elseif($is_NS4) $classes[] = 'ns4';
    elseif($is_safari) $classes[] = 'safari';
    elseif($is_chrome) $classes[] = 'chrome';
    elseif($is_IE) {
            $classes[] = 'ie';
            if(preg_match('/MSIE ([0-9]+)([a-zA-Z0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $browser_version))
            $classes[] = 'ie'.$browser_version[1];
    } else $classes[] = 'unknown';
    if($is_iphone) $classes[] = 'iphone';
    if ( stristr( $_SERVER['HTTP_USER_AGENT'],"mac") ) {
             $classes[] = 'osx';
       } elseif ( stristr( $_SERVER['HTTP_USER_AGENT'],"linux") ) {
             $classes[] = 'linux';
       } elseif ( stristr( $_SERVER['HTTP_USER_AGENT'],"windows") ) {
             $classes[] = 'windows';
       }
    return $classes;
}
add_filter('body_class','mv_browser_body_class');

 

Do not ever use the guid element for creating links – ever – ever

I was recently (I always seem to start posts with that phrase) learning how to update a clients posts post_title, slug (aka post_name in the db) and guid when a post title was changed programatically. I was using get_sample_permalink() in combination with wp_update_post() to generate a permalink and update the post guid along with the … Continued

Force Post Author Comments to Moderation in WordPress

By default in WordPress when an author of a post comments on their own posting the comment is automatically approved. This makes sense when authors are associated with the site, have access to admin, etc. There are cases where content from the general public is used to create posts and while the user is logged … Continued

Allow html in Contact Form 7 error messages

Contact Form 7 has a filter where one can alter the messages being sent back to the browser called wpcf7_validation_error. A simple htmlspecialchars_decode altering the $message variable before returning will do the trick. This function will run on any error for any form you have in your site (any CF7 form that is). If you … Continued

Jetpack 404 not found: devicepx.js

Jetpack 404 not found: devicepx.js

While setting up this site I noticed some files not found errors in dev console. One was devicepx.js which was in the jetpack modules path. It’s used to optionally load retina/HiDPI versions of files. I believe it would be for gravatars and since this site doesn’t use gravatars I deemed it unnecessary. //remove unecessary queing … Continued

Earliest WordPress Hook Where Global $post Variable Exists

In the file wp-includes/class-wp.php there is a hook run which is simply named 'wp'. This, as far as I can tell, seems to be the earliest hook in which the $post object variable exists. The hook is passed the &amp;$this object which the comments state: references the WP object. It allows for accessing the properties … Continued