19 October 2015

WordPress Menu Items Limit

I’m not sure if its well known, but we found few articles about this topic – If you are using WordPress and have like bunch of navigation menus, there is a big chance, that your will run to the limit, where you cannot add any more navigation items. Actually, your WordPress navigation menu items might be lost after save, out of the blue sky.

How WordPress handle menu items?

nav-menu-2 On the left image, you could see one WordPress menu item. This one particular item contains a lot of input fields. You can see 6 of them (url, title, etc…), but there are as well another 6 hidden inputs. So together it’s 12 input fields for 1 wordpress menu item. When you hit the save button, your web browser will process this form and send it to the server. And in this step happens the vanishing magic.

Why are my WordPress menu items misssing?

Every modern PHP server has setting called “max_input_vars”. It’s a number and default value is usually 1000. This setting means, that your PHP/Apache server will accept only first 1000 variables sent from the client. The rest is simply ignored. This setting is relatively new, it was introduced in PHP version 5.3.9, which was released at january 2012. It has been incorporated into the PHP to avoid DDoS (denial of service) attacks, which will simply sent huge amount of PHP Post variables and then flood the server. This is the reason, why your WordPress menu items are disappearing! Count with me, one of your WP Menu Item consume 12 POST variables (6 visible + 6 hidden inputs). Theoretically, you could do the math like 1000 / 12 = 83 menu items. But WordPress is also occupying few other POST variables, so this mean that you could save safely like 70 – 80 menu items.

So after you cross the magical border, and add more than 80 items, they won’t save. You will be confused, because some of your WordPress menu items simply get ignored by the PHP server and wont be saved at all. Worse situation is, if you purchased some template from themeforest, which comes with demo content. You simply install huge load of menu items and everything appears to be ok. After while, you go to your WordPress Admin -> Appearance -> Menu, and hit the save button. Bam! half of yuor menu items are gone

How to fix WordPress menu item limit

Basically you have 2 options here:

A.) Open your PHP.ini file, search for “max_num_vars” and try to enlarge the value from 1000 to 3000 for example. But not every time you have access to the PHP.ini

B.) Use our WordPress Menu Item Limit Fix plugin. It’s no hustle – you simply activate the plugin and thats it :-)

16 September 2015

How to make links in your WordPress Twitter widget clickable

When Twitter changed API to 2.0 and disabled the old one, we adapted to it. But with the adaptation comes small problem – you can gain the tweets, but only as a plain text, without already prepared and existing nice links to your profiles, hashtags and linkify the content of the twitter widget itself. I made a screenshots for better imagining this issue:

tweet with links

Tweet with links

So above is a standard tweet from twitter, which has all the nice links and stuff. Below you can see this very same tweet, just gathered from Twitter API in our Milo – Responsive and Multipurpose WordPress Theme


Plain text tweet – without linkification

Types of linkes in tweet

  • Twitter Username – always starts with “@”, and it should point to http://www.twitter.com/USERNAME
  • Hashtag – always starts with “#” and should point to http://www.twitter.com/hashtag/HASHTAG_NAME
  • Standard link – starting with http, https, www and point to the original address of the link

Regular expression for linkify username in tweet

This regexp makes the job:

$text = preg_replace('/(?<=^|\s)@([a-z0-9_]+)/i',
				'<a href="http://www.twitter.com/$1">@$1</a>',

Regular expression for linkify hashtag in tweet

For hashtag is the regexp pretty different

$text = preg_replace('/(#\w+)/i',
				'<a href="http://www.twitter.com/hashtag/##_replace_#$1">$1</a>',

Regular expression for linkify normal links in tweet

The true fun starts, when you need to convert all strings starting “http, https and www” and having structure of link to actual website link with standard “a” tag. We will be using the “preg_replace_callback” function for finding the links and replacing the links in our WordPress widget. I extracted these two functions from our OOP framework, so it wont work for you out of the but you will have to change the method names.

This is the first method, which actually finds the links based on regexp, and they are passed into callback

private function _linkify( $text ) {
	$pattern = '(?xi)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))';
	return preg_replace_callback("#$pattern#i", array($this,'_linkify_helper'), $text);

And here goes the callback:

public function _linkify_helper($matches){
	$input = $matches[0];
	$url = preg_match('!^https?://!i', $input) ? $input : "http://$input";
	return '<a href="' . $url . '" rel="nofollow" target="_blank">' . "$input</a>";

So this is basically how the tweet looks like, after passing it trough the regular expressions, written above:


Tweet with links created by regular expression

Twitter Feeds