Posted on Leave a comment

WordPress Simple Latest Posts Shortcode Plugin

Wordpress Logo

Although there exist numerous WordPress plugins for integrating the latest posts into pages this new Simple Latest Posts Shortcode Plugin was created to specifically serve those people who just want to have a single line of shortcode in order to display the latest posts in their blog. Nothing more, nothing less.

And yes, there also will be a settings page for the plugin in the administration area of you WordPress just in case you want to customize the way the plugin behaves. This plugin is inspired by the Simple Random Posts Shortcode WordPress Plugin that I released earlier. Based on the great feedback via mail I’ve decided to add this Simple Latest Posts Shortcode Plugin too.


Below you see the Simple Latest Posts Shortcode Plugin in action. It is called with the shortcode


without parameters: [simple_latest_posts]


Feel free to download the Simple Latest Posts Shortcode Plugin via the WordPress plugin repository.

Posted on Leave a comment

Manually update WordPress

Wordpress Logo

So you want to manually upgrade your WordPress installation since the one-click update option is not available due to an ancient (pre 2.7) version or missing file permissions. Although using the one-click update option is the most comfortable one you can almost as easily update WordPress manually. The following steps show you how to manually update WordPress.

Backup database

As usual make a backup of your database and your files. In case you don’t have access to tools such as phpMyAdmin or a shell terminal with proper permissions to export your database have a look at Shuttle-Export, which is an easy to use PHP based MySQL dump library. Make sure to remove this tool after the upgrade process again or protect it with .htpasswd since you most likely don’t want strangers to export your database.

Deactivate plugins

Next, before removing files from your existing installation make sure to deactivate all plugins.

Remove existing installation files

Once again, make sure you have backed up your data and deactivated your plugins. Then remove all files and folders except the following from your installation:

  1. /wp-content
  2. /.htacess
  3. /wp-config.php

Copy new files

Afterwards, copy all files and folders from your new WordPress version, thus overwriting existing files except the ones mentioned above.

Database upgrade

Now it’s time to check if a database upgrade is necessary. Thus, navigate to /wp-admin/. If your are asked click on the upgrade database button. Once this is done click continue and re-login into the dashboard as admin.

Final checks

Finally, check your settings and enable your plugins again. Also check for possible plugin updates. This is all there is to manually updating WordPress. Almost as easy as the one-click update, right? Make sure to remove or password protect your Shuttle-Export installation. You’re all set!

Posted on Leave a comment

Switching WordPress to https only

Wordpress Logo

As you might have seen I’ve switched this site to https only. The steps involved in switching WordPress to https only are pretty simple.

Set Site URL

First, make sure to set the proper https site URLs. You find these options under Settings » General: Wordpress set site URL to https

Redirect non-https traffic

Second, make sure to redirect all non-https requests to https-only in your .htaccess file. In the example below I’ve included an automatic redirect to the www subdomain for the SSL certificate. You can safely ignore this step in case you have a different setup:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Update media URLs

Afterwards, you (probably) need to update the URLs of your referenced media files in your blog posts/pages. Do so by issuing the following command (of course replace with your proper domain):

UPDATE wp_posts SET post_content = 
replace(post_content, '', '');

Update template and plugins

Finally, you need to make sure that your theme and respective plugins do not statically reference any http-only files, e.g., etc. For instance, for the tiga-theme that this site’s is derived from you need to overload the Google fonts URL set by enqueue.php (replace http:// with // only):

wp_enqueue_style( 'tiga-font', 
null, TIGA_VERSION, 'all' );

That’s it 😉

Posted on 6 Comments

Simple Random Posts Shortcode WordPress Plugin

Wordpress Logo

A simple but effective WordPress plugin to render random blog posts in pages and/or posts. This is the first public release and features the following shortcode options to customize the rendering process:

  1. header: whether to output header text (default=)
  2. show_featured_image: whether to output featured post image (default=TRUE)
  3. featured_image_height: height of featured image in px (default=100)
  4. preview_text_chars: amount of chars to be displayed for preview text (default=200)
  5. container_css_class: CSS class of outer container (default=articles-preview-container)
  6. container_article_css_class: CSS class of article containe (default=article-preview)
  7. append_css_clear: whether to append a CSS clear container (default=TRUE)
  8. container_left_width: px or % (default=65%)
  9. container_right_width: px or % (default=30%)


In order to use the plugin just insert the shortcode


and use the options provided above to customize the plugin. Feel free to download it from the official WordPress plugin repository.


Below you find a demo using the following shortcode:

simple_random_posts header="<b>Custom header</b>

[simple_random_posts header=”Custom header“]

Posted on 1 Comment

Custom WordPress Permalinks Are Causing 403 or 404 Errors

Wordpress Logo

When settings custom permalink structures in your WordPress settings make sure to

  1. either make .htaccess writeable by your webserver so that when saving your custom structure via the backend WordPress will automatically update your .htaccess too
  2. or manually edit your .htaccess file with the minimal required mod_rewrite rules as shown below, right after setting your custom permalink structure via the backend
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Also, make sure that your RewriteBase setting is correct.

In case you experience 403/404 errors after setting your custom permalink structure here is what you can do:

  1. open options table from database and locate the permalink_structure field
  2. clear its value and save the entry
  3. remove the above mod_rewrite content from .htaccess
  4. make .htaccess writeable by your webserver
  5. reload your backend URL (/wp-admin)

This way you can reset your permalink structure to “Default” setting and start over again.

Posted on 1 Comment

WordPress search redirects to home when search query is empty

Wordpress Logo

By default, WordPress redirects users with empty search queries to the home page – which might not be what you are looking for.

To overcome this behavior and redirect users to the search results page regardless of empty search queries we need to adjust the way WordPress processes search queries. As always, this can be done via functions.php:

function searchRequestFilter( $query_vars ) {
    if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
        $query_vars['s'] = " ";
    return $query_vars;

add_filter( 'request', 'searchRequestFilter' );

As you can see we simply add a filter named searchRequestFilter that intercepts search requests and checks for empty queries. In order to prevent recursion we replace the empty search query with a single space character (” “).

Finally, we need to adjust our search form to handle “empty” search queries, i.e. by removing the forced space from functions.php, like so:

<form class="searchform" 
      action="<?php echo esc_url(home_url('/')); ?>">
    <label for="s" class="searchLabel assistive-text"><?php echo icl_t('Search', 'Search', 'Search'); ?></label>
    <input type="text" class="search-query" name="s" value="<?php echo trim(esc_attr(get_search_query())); ?>" id="s" placeholder="">

That’s it! This way your users are able to submit empty search queries and are still redirected to the search results page.

Posted on Leave a comment

Using Custom Menus in WordPress Themes

Wordpress Logo

If you are creating WordPress themes from scratch and only won’t to include basic features at first enabling custom menus is a good thing to start with. Out of the box new WordPress themes do not support specifying and displaying custom menus, which you might have seen and used through the admin interface before:

In order to enable your themes to handle and display custom menus correctly only a few steps are required.

The Steps to Success

The first thing you need to do is to create functions.php (if you not already have) and add the following function:

function custom_register_nav_menu() {
    register_nav_menu('primary', __('Primary Menu', 'your_theme'));

add_action('init', 'custom_register_nav_menu');

Second, you must specify the location where your shiny new custom menu should be displayed in your theme. Therefore, locate the proper location and insert the following code:

&amp;lt;div id=&amp;quot;navcontainer&amp;quot;&amp;gt;
  &amp;lt;ul id=&amp;quot;navlist&amp;quot;&amp;gt;
    $menu_items = wp_get_nav_menu_items('Default');

    foreach ((array) $menu_items as $menu_item) {
      $title = $menu_item-&amp;gt;title;
      $url = $menu_item-&amp;gt;url;
      echo '&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;' . $url . '&amp;quot;&amp;gt;' . $title . '&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';

In case the loop is too much code for you and you want to simply style the outcome produced by WordPress’ core use the following code:

wp_nav_menu(array( 'theme_location' =&amp;gt; 'Primary Menu'));

That’s all there is to it, easy right?

Posted on Leave a comment

WordPress Plugin for checking Compatibility prior to Upgrade

Wordpress Logo

Like with every good piece of software updates and upgrades are mandatory to keep up-to-date with the latest features and security fixes. Since WordPress offers a vast range of plugins to extend its core functionality these plugins should be kept up-to-date too. Now, to be able to use these plugins after a WordPress upgrade it is important to carry out prior compatibility checks not to break any existing functionality.

Especially if you have numerous plugins installed this check can be time consuming. Thus, it would be nice to have another plugins doing exactly these checks in advance – that’s where Better Plugin Compatibility Control (BPCC) comes into play. BPCC nicely formats the list of currently installed plugins and provides information on the compatibility.

Another useful plugin when it comes to updates and upgrades is Changelogger. This handy plugin saves you some time by displaying changelogs messages for each plugin in the list view.

Using these two plugins managing WordPress upgrades and plugin updates has become much more comfortable and easier.

Posted on 2 Comments

Language selection in WordPress using qTranslate plugin

Wordpress Logo

qTranslate is a very handy and powerful i18n plugin for WordPress. In order to enable visitors of your WP site to switch between languages you need to include qTranslate’s widget. Following you find the necessary steps to do so.

  1. Install qTranslate (
  2. edit the plugin settings to enable/disable your supported languages
  3. edit your WP layout template (e.g. sidebar.php) and add to qTranslate widget:
    echo qtrans_generateLanguageSelectCode('both');

Currently, the qTranslate widget supports to following styles:

  • image
  • dropdown
  • text
  • both

For more information on the parameters of qtrans_generateLanguageSelectCode have a look at plugins/qtranslate/qtranslate_widget.php.

If you are looking for a plugin to support multilingual text have a look at the gText widget which works like a charm in combination with qTranslate.

Posted on 2 Comments

Fix for date format bug in comments section of zbench WordPress theme

Wordpress Logo

There exists a bug in the zbench WordPress theme when used together with qtranslate plugin resulting in a malformed date string in the comments section. Fortunately, there exists a quick fix for this problem.

Simply replace corresponding code with the following in the function mytheme_comment in functions.php:

<?php echo mysql2date('Y/m/d/ H:i', $comment->comment_date);?><?php edit_comment_link(__('[Edit]','zbench'),' ','') ?>

Pay special attention to

<?php echo mysql2date('Y/m/d/ H:i', $comment->comment_date);?>

which replaces

<?php printf(__('%1$s at %2$s', 'zbench'), get_comment_date(),  get_comment_time()); ?>

That’s it, enjoy!

Posted on Leave a comment

WordPress custom blog page

As of this writing I have finally decided to create a custom blog page for this WordPress installation to provide users with a more handy access to all blog posts rather than solely relying on the recent post category on the right hand side.

In order to create a custom blog page in WP simple create a new page as you would do normally. Then, as administrator open the Settings menu and navigate to the Reading section. There you can select the front and post page to be displayed. I have selected my “Home” page as front page and a newly created “Blog” page for postings. Voila – sometimes things can be pretty easy 🙂

Posted on 3 Comments

How to control error pages in WordPress

Wordpress Logo

By default WordPress searches for error pages, such as error 404 (file not found) or error 403 (permission denied), in the current active theme (e.g. 404.php or 403.php). If the theme does not provide default error pages WordPress’ built-in ones will be used instead.

Since I tend to deploy other web applications alongside WordPress, my overall goal was to have the same error pages independent of the application context in order to achieve a standardized representation. Thus, for instance if a page cannot be found the current WordPress layout will be used to present the error.

Using Apache default error pages can be controlled via .htaccess files. So first, create these custom links to your error pages:

ErrorDocument 403 http://your.server/error-403-permission-denied
ErrorDocument 404 http://your.server/error-404-file-not-found
ErrorDocument 500 http://your.server/error-500-internal-server-error

The next step is to create these WordPress error pages:


Finally, in your currently active theme create the corresponding error pages:


Finally, all you need to do is to redirect to the link specified in .htaccess inside your theme’s error pages, e.g. for 404.php:

header('Location: http://your.server/error-404-file-not-found');

That’s it. Now you have a standard layout for error pages independent of the application context on your server.

You can try it on this site by requesting a non-existing file, such as

Further improvements could be made for sites with multiple languages, for instance by prepending the language when redirecting via the corresponding error pages.