PHP

If you want to prevent client from switching WP theme by accident, use this WP snippet, brought to you by SoulSizzle design. Just put this code into your functions.php file, and users won’t have an option to switch theme in WP. 1 2 3 4 5 6 7 add_action(’admin_init’, ‘remove_theme_menus’); function remove_theme_menus() { global $submenu; [...]

PHP user agent

In: PHP

8 Jul 2010

Many websites would not deliver you content if you came presenting as a wrong user agent. In PHP there are ways to present yourself as someone else if you are going to crawl somebody’s website. In this snippet we show you how to use PHP user agent settings in cURL, and trick server to think [...]

JS include

In: JavaScript|PHP

6 Jul 2010

In order to lower down number of http requests and speed up your website, you can use regular JS include, to include PHP file. <link rel="javascript" type="text/javascript" href="alljs.php"> PHP JS include file This is how PHP file, that includes all JS files you want to be included, should look on your server: 1 2 3 [...]

Redirection htaccess

In: PHP

5 Jul 2010

Considering that you want to have nice URLs that are SEO optimized, you would have to pass parameters without using “?”. In this case we can use redirection htaccess. To make simple example, see snippet below: 1 2 3 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page=$1 Use redirection htaccess: This redirection snippet will [...]

Zend date

In: PHP

5 Jul 2010

To format Zend date by local settings of your multilingual website can be done easy if you are using following script. This script shows you a simple usage of Zend date you will be using when want to format date according to locale settings of current language on your multilingual website. 1 2 $date = [...]

PHP change date

In: PHP

3 Jul 2010

If you want to use PHP to change date. 1 2 3 4 5 6 function php_change_date($number_of_days, $from_date) { $date = new DateTime(); $date->setDate($from_date); $date->modify($number_of_days . ‘ days’); return $date->format("Y-m-d"); } Example of usage: You want to know what will be date in 40 days from now, you will use PHP change date like: echo [...]

PHP update Twitter

In: PHP

2 Jul 2010

To use PHP update Twitter status, all you need is following function. Call this function from your PHP application sending your Twitter username, Twitter password, status, and link to a source you want to link. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [...]

PHP compress file

In: PHP

2 Jul 2010

PHP compress is possible since version PHP 3, using zlib. In order to compress file with PHP, just use following function. Function uses two parameters: source of file, and destination of compressed file. 1 2 3 4 5 6 7 8 9 10 function compressFile($sourceFile, $destinationFile) { $file = fopen($sourceFile, ‘r’); $data = fread ($file, [...]

To remove WordPress tag from your WordPress theme, insert following line in you functions.php 1 remove_action(’wp_head’, ‘wp_generator’);

Zend Feed

In: PHP

30 Jun 2010

To create RSS Feed using Zend Feed, you can use following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 $items = array(0, 1, 2, 3);   foreach ($texts AS $text) $items[] = array( ‘title’ => ‘Zend Feed title’, ‘link’ => ‘http://example.com’, [...]