[WordPress] filter out unneeded menu classes

Here’s a code snippet for WordPress to filter out unneeded menu classes. Put the following line in your functions.php

// Reduce nav classes, leaving only 'current-menu-item'
function nav_class_filter($var)
    return is_array($var) ? array_intersect($var, array(
    )) : '';
add_filter('nav_menu_css_class', 'nav_class_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);

[WordPress] set cookie

Here’s a code snippet for WordPress. Since WordPress doesn’t support any sessions a cookie might be useful. Here’s a code snippet to use for your functions.php

//Set cookie
function set_newuser_cookie() {
	if (!isset($_COOKIE['sitename_newvisitor'])) {
		setcookie('sitename_newvisitor', 1, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
add_action( 'init', 'set_newuser_cookie');

[WordPress & Genesis] Add parent and child classses to menu

Here’s another code snippet for WordPress Genesis Framework.

If you would like to add menu classes to parent and child menu’s, use the code below.
Put this in the functions.php file:

// Function to add parent and child classses to menu
class Arrow_Walker_Nav_Menu extends Walker_Nav_Menu
    function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
        $id_field = $this->db_fields['id'];
        if (0 == $depth) {
            $element->classes[] = 'menu-top'; //top main menu
            if (empty($children_elements[$element->$id_field])) {
                $element->classes[] = 'menu-noparent'; //no childs
        if (!empty($children_elements[$element->$id_field])) {
            $element->classes[] = 'menu-parent'; //child in menu
        Walker_Nav_Menu::display_element($element, $children_elements, $max_depth, $depth, $args, $output);

[WordPress & Genesis] Add menu classes to first en last menu items

Here’s a code snippet for WordPress Genesis Framework.

If you would like to add menu classes to first en last menu items, use the code below. Put this in the functions.php file:

// Function to add menu classes to first en last menu items
function add_first_and_last($items)
    $items[1]->classes[]             = 'menu-first-item';
    $items[count($items)]->classes[] = 'menu-last-item';
    return $items;
add_filter('wp_nav_menu_objects', 'add_first_and_last');

[WordPress & Genesis] custom viewport

Here’s a code snippet for WordPress Genesis Framework.

If you would like to use a custom viewport for mobile devices, for example, use the code below:

/** Add Viewport meta tag for mobile browsers */
add_action('genesis_meta', 'add_viewport_meta_tag');
function add_viewport_meta_tag()
    echo '<meta name="viewport" content="width=1020">';

[WordPress & Genesis] custom footer or custom header

Here’s a code snippet for WordPress Genesis. If you would like to use a custom header or custom footer, don’t use any header.php of footer.php. Use the code snippet below:

// Include Header, seperate from functions
include 'custom-header.php';

// Include Footer, seperate from functions
include 'custom-footer.php';

[Synology] How to secure photostation with htaccess

Here’s a short instruction on how to protect your synology photostation by using htaccess:

Create the following file: /volume1/@appstore/PhotoStation/photo/.htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /volume1/@appstore/PhotoStation/photo/.htpasswd
AuthGroupFile /dev/null
require valid-user

and the following file: /volume1/@appstore/PhotoStation/photo/.passwd


Use the passwd htaccess online generate for your own password.

Synology: Monitoring Apache with mod_status

Here another quick manual. If you would like to monitor your apache webserver, you can do that with mod_status. Open the httpd.conf-user file:

pico /usr/syno/apache/conf/httpd.conf-user

Copy paste the following content from below:

<Location /server-status>
   SetHandler server-status
   Order Deny,Allow
   Deny from all
   Allow from all

Save the httpd.conf-user file and restart apache with:

/usr/syno/etc/rc.d/S97apache-user.sh restart

You can now obtain the apache server status by querying the following url:


This might be useful for people working with cacti.

Synology: Run sabnzbd behind apache

Here’s a quick instruction for those who would like to run sabnzbd behind apache on a synology nas system. Open up a ssh connection, create the following file:

nano /usr/syno/etc/sites-enabled-user/sabnzbd.conf

Copy paste the contents below to this file. Please note that my sabnzbd port is 9090. If you would like to change this, change the config file below.

# Put this after the other LoadModule directives
LoadModule proxy_module /usr/syno/apache/modules/mod_proxy.so
LoadModule proxy_http_module /usr/syno/apache/modules/mod_proxy_http.so

<Location /sabnzbd>
order deny,allow
deny from all
allow from all
ProxyPass http://localhost:9090/sabnzbd
ProxyPassReverse http://localhost:9090/sabnzbd

Save the file by using control-x. Restart apache with the following command:

/usr/syno/etc/rc.d/S97apache-user.sh restart

Useful rc.local script on synology

Here’s a useful rc.local script which restores the optware (ipkg) functionality after an upgrade:


#optware fixes http://forum.synology.com/enu/viewtopic.php?f=189&amp;t=46095
mount -o bind /volume1/@optware /opt

# remount with noatime
mount -o remount,noatime /
mount -o remount,noatime /volume1

# enable debug spindown
syno_hibernate_debug_tool --enable 10

# Optware setup
[ -x /etc/rc.optware ] && /etc/rc.optware start

# configure ssh to run on 443
if ! grep "Port 443" /etc/ssh/sshd_config ; then
sed -i "s/Port 22/#Port 22/g" /etc/ssh/sshd_config
echo 'Port 443' &gt;&gt; /etc/ssh/sshd_config
/usr/syno/etc.defaults/rc.d/S95sshd.sh restart

# restore /opt/bin path
if ! grep "/opt/bin" /root/.profile ; then
sed -i "s/PATH=/PATH=\/opt\/bin:/g" /root/.profile

exit 0

Howto to authenticate with apache against the /etc/passwd file

I used the following files to let apache authenticate against the local /etc/passwd file.

The perl-pass.nl is used to generate a file based on the /etc/passwd and shadow file. You can place this in the crontab for example. Only the lower id’s are used, so root won’t be in the list.

The index.php reads from the passwd.html file generated by the perl script and will redirect the users to welcome.php when a correct password and username are used.



        if ($temppass ne 'x'){ $pass{$uname}=$temppass; }
        if ($uid>=500) {
                print FLATFILE



<? session_start() ?>

<p align="center"><br><br>
<br><br><b>Welcome to Server Manager</b>
<table align="center" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<form method="POST" action="index.php">
  Username: </td><td>
  <input type="text" name="username" size="19"></td></tr>
  <tr><td>Password: &nbsp;</td><td>
  <input type="password" name="password" size="19"></td></tr>
  <tr><td colspan="2" align="center">
    <br><input type="submit" value="Login">


// Var
$user = ($_POST['username']);
$pass = ($_POST['password']);
$autharray = file("/var/www/passwd.httpd"); 

// Check passwd
for ($x = 0; $x < count($autharray); $x++)
   if (eregi("^$user:", $autharray[$x])) {
       $passwd = explode(":", $autharray[$x]);
       $salt =  substr($passwd[1],0,11);
       $cryptpw = crypt($pass,$salt);
       if ($cryptpw == $passwd[1]) {
		// Succes
             	echo "<br><p align='center'>Username found on</p>";
		echo "<br><p align='center'>Starting connection: $_SESSION[user]...   Moment Please.....</p>";
		$_SESSION['user'] 		= $user;
		$_SESSION['server'] 		= $servername;
		if ( $_SESSION['user'] == "admin" ) { 
			echo" <META HTTP-EQUIV='Refresh' CONTENT='1; URL=admin_overview.php'> ";
		} else {
			echo" <META HTTP-EQUIV='Refresh' CONTENT='1; URL=welcome.php'> "; 
            } else {
		// Error on password
              	echo "<br><p align='center'>Wrong password or username!</p>";


<? session_start() ?>


if ( $_SESSION[user] == "" ) { 
   echo "No Access!"; 
} else {
   echo "Welcome $_SESSION['user']</b><br><br>";