06th May2016

WP Lightbox stopped working – jQuery version the culprit.

by Gyro

I just spent a while trying to figure out why a lightbox stopped working on a friend's WP site.

Supposedly nothing had changed… and looking at the code, everything looked ok.

After some trial and error, I finally figured out that the issue was with the jQuery version, the site was loading version 1.2.1, which apparently does not work with the lightbox plugin. I tried jQuery version 2.0.2, but that seems to have been too much, so I finally settled on jQuery version 1.7.1 which seem to work well with any jQuery script junning on his site.

An easy way to manually set this jQuery version in WordPress is adding some code to the theme's functions.php:

function modify_jquery_version() {
if (!is_admin()) {
wp_deregister_script(‘jquery');
wp_register_script(‘jquery', ‘http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, ‘1.7.1');
wp_enqueue_script(‘jquery');
}
}
add_action(‘init', ‘modify_jquery_version');

Just change the version numbers 1.7.1 to the one you need.

34

06th May2015

Simple “Are you sure?” warning for unsaved changes in WP

by Gyro

I spent quite a few hours getting a seemingly simple piece of javascript to work in a WP plugin I am currently working on.

Naturally, I started with jquery as it is already included in the WP Admin, but after several hours of trying various solutions I found on the web I had to admit defeat. I just could not get it to work the same way it obviously worked for others using jquery.

So, I ended up looking around a bit to find all natural javascript to do this.

function myplugin_js() {
echo ' <script>
window.onload = function(){
var theform = document.myform;
window.onbeforeunload = function(e){
var e = e || window.event, simon = "go";
for (i=0; i<theform.elements.length; i++){
if(theform.elements[i].type == "radio" || theform.elements[i].type == "checkbox"){
if(theform.elements[i].checked != theform.elements[i].defaultChecked){simon = "no";}
}else if(theform.elements[i].type == "select-one"){
if(!theform.elements[i].options[theform.elements[i].selectedIndex].defaultSelected){simon = "no";}
}else if(theform.elements[i].type == 'submit'){
theform.elements[i].onmouseup=function(){
simon = 'go';
}
}else{
if(theform.elements[i].value != theform.elements[i].defaultValue){simon = "no";}
}
}
if(simon != "go"){if(e){e.returnValue = "unsaved chages detected";}return "unsaved chages detected";}
}
};
</script>';
}
add_action('admin_enqueue_scripts', 'myplugin_js');

You can put this in a theme functions.php or in your plugin file.

This will cause a warning message to popup whenever the form with the name "myform" was modified and one attempts to load a new page.

Change ‘admin_enqueue_scripts' to ‘wp_enqueue_scripts' to enable this feature on the front-end of your website.

If you use a select element, make sure you have a default option "selected", else the script will fail.

Enjoy :crazy:

Sources:

275

30th Jun2014

Using qTranslate with WordPress 3.9++

by Gyro

I've been a long time fan of Qian Qin's qTranslate plugin, which allows you to translate just about everything you need to have a multilinugal website running on WordPress.

Unfortunately, he seems to have fallen off the face of the earth since WordPress Version 3.9 came out, so installing the plugin will result in its automatic deactivation, as the only available qTranslate version has not been officially tested with any WordPress version newer than WP 3.8.1 :(

I've been waiting for an update for months now, and I have come to the realization that I may have to wait a lot longer. So, I decided to see what I can do with this plugin to make it work again. Turns out, there are two simple file modifications needed in order to make qTranslate work with WordPress 3.9.1, which is the newest WP version that is available while I am writing this post.

If a new WP version is released, come back here to check if this fix/hack still works, BEFORE you update your WP installation.

Should there be a newer version available than WordPress Version 3.9.1, please write a comment. I will reply with a status report asap!

qTranslate WordPress 3.9 Fix

Short Question: So, what is there to do?

Short Answer: You have to modify two files in the /qtranslate/ plugin folder (via ftp).

1. Modify qtranslate.php

change this:

define('QT_SUPPORTED_WP_VERSION', '3.8.1');

to this:
define('QT_SUPPORTED_WP_VERSION', '3.9.1');
which allows activating qTranslate up to WordPress version 3.9.1.

You could also do this:

define('QT_SUPPORTED_WP_VERSION', $wp_version);
which allows activating qTranslate on EVERY new WordPress version. Warning: qTranslate may be incompatible with future WordPress versions and break your website! I highly recommend the first option.

2. Modify qtranslate_core.php

change this:

function qtrans_dateFromPostForCurrentLanguage($old_date, $format ='', $before = '', $after = '') {
global $post;
return qtrans_strftime(qtrans_convertDateFormat($format), mysql2date('U',$post->post_date), $old_date, $before, $after);
}

to this:
function qtrans_dateFromPostForCurrentLanguage($old_date, $format ='') {
global $post;
return qtrans_strftime(qtrans_convertDateFormat($format), mysql2date('U',$post->post_date), $old_date);
}

And that's already all there is to it! :)

Enjoy!

p.s. You may want to add this to your functions.php, it will increase the width of menu items in the admin… these tiny input fields drove me insane! :crazy:

add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
.menu-item-bar .menu-item-handle {
width: 582px;
}
.description-thin {
width: 550px;
}
.menu-item-settings {
width: 602px;
</style>';
}

Sources:
http://wordpress.org/support/topic/the-qtranslate-editor-has-disabled-itself-because-it-hasnt-been-tested-with-you
http://alexander.kirk.at/2014/04/17/fix-qtranslate-with-wordpress-3-9/
http://css-tricks.com/snippets/wordpress/apply-custom-css-to-admin-area/

1493

15th Dec2012

WordPress 3.5 – PHP Warning: Missing argument 2 for wpdb::prepare()

by Gyro

I just updated a work in progress to WordPress 3.5, and ended up with broken permalinks (to fix that: reset to default permalinks, then set the custom permalinks again), and my favorite plugin "Network Shared Posts" gave a super-long error message on each page, something along the lines of
PHP Warning: Missing argument 2 for wpdb::prepare()…blablabla…

So, after doing some research I found out that the root of all evil are the WordPress developers! Or to be more precise, they decided to make their functions more strict, resulting in a lot of plugins now showing the error "PHP Warning: Missing argument 2 for wpdb::prepare()", after someone updates to WordPress 3.5 and before the author has the chance to update, or in some cases totally rewrite their plugin. Read this article for more on this.

Here is my work-around to literally hide all "PHP Warning: Missing argument 2 for wpdb::prepare()" error messages:

(more…)

1284

07th Nov2012

Top Level Categories vs WP No Category Base for WordPress

by Gyro
Today I had to switch a plugin, so I decided to write a little Top Level Categories vs WP No Category Base for WordPress. The reason for the plugin change is, that Top Level Categories has an issue with sub categories.

I installed Top Level Categories yesterday, just to realize today that I should have taken the name literal TOP LEVEL CATEGORIES, as it throws 404 errors when trying to view the archive of any sub category… so Top Level Categories is really what it says: It makes categories be top level (no /category/ slug in front of the actual category slug) and there can't be any 2nd level categories… since I am using a lot of sub categories, I cannot use Top Level Categories.

562127_Mojo - 125x125

(more…)

1198

21st Oct2012

Display posts from multiple WordPress Categories – Network Shared Posts

by Gyro
Display posts from multiple WordPress categories with Network Shared Posts.

With Network Shared Posts you can combine posts by categories/tags and display them as if they were one category. You can select the blogs to pull posts from, then define the category slugs and tags to get the posts you want to display. All this is done in one single shortcode featuring an array of settings to further customize the final list of posts. It works perfect to display posts from multiple WordPress categories and tags. You can get the full list of short code arguments on the official website.

This plugin is the perfect companion for any WP Multi Site network, but also works its magic when just running a single block and wanting to combine posts in a way categories and tags simply can't.

With Network Shared Posts plugin you can share posts over WP Multi Site network, you can display the posts from all blogs in your network on any blog, and you can select blogs to display posts from. In short, you can display posts from multiple wordpress categories on one page, including those matching pre-defined tags.

562127_Mojo_250x250_Browse100s

(more…)

1278

14th Aug2012

WordPress Automatic Update not working

by Gyro
I had an issue with WordPress automatic update not working on my localhost, instead it kept asking me to provide ftp login details?!

Even if I had a FTP server installed, which I don't, I prefer to use the Automatic Update Feature that comes with WordPress.

Of course there can be other similar issues leading to problems with updating wordpress, regardless of being installed locally on you PC, or running on a web server on the Internet. Most likely the reason for these problems will be permission errors, that prevent WordPress from saving any files during the update. So the solution will be to change the permissions for the folders in question.

Should you run a web server on your localhost (apache), then try this in the Terminal:

562127_Mojo_250x250_Browse100s

(more…)

1059

07th Aug2012

Create search engine optimized multilingual websites

by Gyro

Using WordPress to create search engine optimized multilingual websites is as easy as baking a pie,if you got all the ingredients and are willing to follow the cookbook. This is a guide on how to install WordPress MultiSite with the essential plugins needed to run a search engine optimized website. Follow this guide to create search engine optimized multilingual websites based on WordPress.

(more…)

1001

06th Aug2012

Multiple WordPress Blogs One Dashboard Setup MultiSite

by Gyro

Today I am setting up a new website that is going to have about 20 different subdomains, each with their own blog about a certain subject. Prior to WordPress 3, you had to use a plugin called WordPress MU (WordPress Multi User or short WPMU), that was then renamed WordPress MultiSite and integrated into WordPress.

(more…)

1012

12th Jun2012

Display Links Categories on WordPress using ShortCodes

by Gyro

While looking for the best way to do what the title says, I stumbled upon this great little function. All you need to do is add it to the current ThemeFunctions.php and then you can display any category anywhere in WordPress.

(more…)

684

21st May2012

Hikari Category Permalink for Posts in WordPress 3

by Gyro

Here comes a great little plugin for WordPress to organize WordPress Categories and Posts!

Hikari Category Permalink allows post authors to choose among each post's categories, which of them is used in that post permalink, giving much more flexibility and power to permalinks.

(more…)

740

19th May2012

How To Use Jquery Lightbox In WordPress

by Gyro

645