Always Redirect User to Translated Pages with the WPML Plugin for WordPress

The Context I recently worked on my first translation site for WordPress. We used the WPML (WordPress Multilingual) plugin. The client wanted to have all pages that had an associated translation automatically have users whom have set their browser language to be redirected to the translated page…every time. There is a setting with the value … Continued

Add a Resize Handle for WordPress Post and Page Edit Sidebar

I was converting some ACF fields to Gutenberg ACF fields and put together some options for how/where content can be edited. The acf_register_block_type() function has the mode option. The allowed values are: – auto: Preview is shown by default but changes to edit form when block is selected. – preview: Preview is always shown. Edit … Continued

Three Things I Tried to Fix a Failing Connection From Ulysses to My Custom WordPress Site

  1. I didn’t actually try this one (misdirection!) but it could be your issue. Shared hosting can block access to the /xmlrpc.php file. This plugin can help you get around that.
    https://wordpress.org/plugins/rename-xml-rpc/
    Be sure to also follow the installation instructions: https://wordpress.org/plugins/rename-xml-rpc/#installation
  2. php-xmlrpc is not installed. sudo apt-get install php-xmlrpc. Then sudo service apache2 restart. Not my issue, but kept on looking.
  3. php-xml not installed. sudo apt-get install php-xml. Then sudo service apache2 restart. This was my issue!

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;
}

[wp_videojs mp4="https://thisbailiwick.com/wordpress/wp-content/uploads/2018/10/taxonomy-resize.mp4"]

Current Project: Stone Roberts

I'm currently working on a site redesign/development for the painter Stone Roberts. There isn't anything to be seen as of yet, but there is a Github repo I'll keep updated as I go along. More info can be found on it's project page. [wp_videojs mp4="https://thisbailiwick.com/wordpress/wp-content/uploads/2018/08/D19C48CE-9BF3-4612-8073-A8689D30A623.mp4"]   [wp_videojs mp4="https://thisbailiwick.com/wordpress/wp-content/uploads/2018/08/45550155-8898-48FB-B39E-AC9092DD5769.mp4"]

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