Category: Tech Blog

My Favourite WordPress Extensions Plugin Add on

  • Peter’s Post Notes
    Great for adding random notes to posts, pages, of the Admin dashboard section. You can add more, edit them, and yeah – just text.
  • PHP Execution
    ability to add <php something; ?> PHP scripts in the “HTML” section of pages and posts, but there are bugs… maybe I’ll try to find another one – I’ve had problems with this sort of thing before… I’ll keep looking…
  • TinyMCE Advanced
    Advanced text editing options, really useful.
  • Simple Meta Tags – ability to add your own Title, Description, Keywords to each page or defaults.
I’m sure there are lots of amazing things out there – and I love WordPress in general
What do you use? What web tools do you love?

Getting into a server with SSH, seeing stats etc.

I recently had some troubles with a dedicated server that is hosting many websites at work, hosted with another company, which was getting a lot of traffic to huge table heavy websites. The server couldn’t handle the load and all websites were slowing down a lot.

Here is some useful hints on how to access the terminal of the server and find some stuff out ~

  1. Download win SCP used for SSH-ing into the server
  2. Type the IP address and port 22 (for the server), then click login
  3. It will then ask you for username and password.
  4. You can login as ROOT for all privileges, but make sure you don’t mess with the config files, or you could break a website.. or all of them…
  5. Type “top” to see a running list of the top processes and some stats on RAM, CPU etc. (like task manager on windows)
  6. Press “c” to also see which files are causing the CPU load… (maybe it’s a MySQL script in “display.php” or something like that..
  7. You can check MySQL information by typing “mysql” and then you may need to login with those details (not if you’re logged in as ROOT)

WordPress template editing Adding custom menu, sidebar, layout etc.

You can edit a WordPress template so that it is just a HTML file which inserts the body text, but you can use some powerful tools that make the template easier to edit, and more dynamic.

Custom Menu

You can use a custom menu to make the header links, sidebar links, footer links, or other list of links to pages.

You can add, remove, reorder these links in the WordPress admin section, so no need to sift through code, or edit HTML.

  • Just go to the admin section, click on Appearance -> Menus
  • Click the + to make a new menu
  • add a name
  • in the left hand side, you can choose what pages you want to add
  • then drag the items to reorder them
To print a menu, use:
<?php wp_nav_menu( array('menu' => 'Menu Name' )); ?>
This will print an unordered list of the menu items.
You can display them next to each other, change the colour of the current page, and more fancy things using CSS.

Custom Sidebars

You can add different things to the sidebar using widgets
WP-admin -> Appearance -> widgets
You can add a text widget to add your own HTML
This code can be added to your sidebar.php file to print the widgets

<?php
if ( 'content' != $current_layout ) :
?>
<div id="secondary" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyeleven' ); ?></h3>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!– #secondary .widget-area –>
<?php endif; ?>

 

Custom site layouts and structures

You can have different structures to your site. one page with no sidebars, one or two sidebars etc.

Just make different “page.php” files for each layout type, and you can set them in the page settings for each page.

just add
<?php
/*
Template Name: Snarfer
*/
?>

To your custom template

For more info: See the WordPress page on this topic

Custom CSS and Javascript in your Admin Section of WordPress

If you edit files in the admin folder of WordPress – you will lose all changes when you upgrade to a new WordPress version, so just add this to your functions.php file in your current WordPress theme.

/* ADDMING CSS TO ADMIN AREA OF WORDPRESS */
function custom_admin_css() {
echo '
<style type="text/css">
#footer{background:#acacac;}
</style>
';
}
add_action('admin_head', 'custom_admin_css');
/* end - ADDMING CSS TO ADMIN AREA OF WORDPRESS */

SEO Canonical Links redirects rewrites in htaccess without CMS

These are some methods you can use to rewrite URLs, redirect and make URLs SEO search Engine Optimised without using a CMS

#Canonical

#This should be added once above all other rewrites
RewriteEngine On

#Add trailing slashes – PAGE= exception
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !PAGE.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://WEBSITE.com.au/$1/ [L,R=301]
#if you want to add www. to all URLs, add it to the line above

#RewriteEngine On #Add www
RewriteCond %{HTTP_HOST} ^WEBSITE.com.au$
RewriteRule (.*) http://www.WEBSITE.com.au/$1 [R=301]

#RewriteEngine On #Remove www
RewriteCond %{HTTP_HOST} ^www.WEBSITE.com$ [NC]
RewriteRule ^(.*)$ http://WEBSITE.com/$1 [R=301,L]

#RewriteEngine On #Rewrite index.html to index.php
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]

#RewriteEngine On #Rewrite index.php to /
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.WEBSITE.com.au/ [R=301,L]
#if you are removing www, remove it from the above line

#Trailing slash 2

RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([a-zA-Z0-9]+)
RewriteRule ^([a-zA-Z0-9]+)$ /%1/? [R=301,L]

#Rewrite URL

RewriteRule ^new-pretty-url/$ from-original-renamed.php
redirect 301 /original.php /new-pretty-url/

(if you’re making a new website, don’t worry about renaming all fines and redirecting from the original file names… )

Adding a second loop to your WordPress site

You can list blog posts anywhere in your website, by adding a second loop.

Use this code: (edit the category name and number of posts to show – you can also edit what the loop shows, just listing the names of posts, linking to them, or add the summary/content…)

<?php rewind_posts(); ?>

<?php query_posts(‘category_name=NAME&showposts=5′); ?>

<?php while (have_posts()) : the_post(); ?>
<!– Do featured stuff… –>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
<?php // the_excerpt(); ?>
<?php //<div class=”entry”>
// the_content();
//</div>
//</div> ?></li>
<?php endwhile;
//wp_reset_query();
?>
</ul>

<p class=”right”><a href=”/NAME/”>All posts</a></p>

The last link is just a link to the category name so you can show all.

FileZilla Error Too many connections from this IP address Upload files not working

If you get an error in FileZilla or other FTP client, “Too many connections from this IP address” and you can’t upload anything, do this:

  • edit->settings->transfers->
    set maximum simultaneous transfers to 2
    set limit concurrent downloads to 2
    set limit for concurrent uploads to 2

File Zilla FTP Settings

Also

  • Click File->Site Manager
  • go to the FTP address you are having troubles with
  • tab, Transfer Settings
  • check “limit number of connections to 2

And it should be ok.

(The system was making too many connections to the server and it was blocking it…)

How to centre a DIV in HTML CSS for clean Web Design Development

This is what I would use to center a div – are there any other techniques? don’t say <center></center> O__O
<div class=”one”>
<div class=”two”>
</div>
</div>

.one{
text-align:center;
}
.two{
margin: 0 auto 0 auto;
text-align: left;
}

Margin auto for left and right centrers the div (because float:center; doesn’t exist), and the outer layer’s “text-align:center” is for IE bugs… The inner object’s “text-align:left;” is to over-ride the outer centring, so that the text isn’t centred.

Speeding up a MySQL intense server CPU with Query Cache

Query caching for MySQL can speed queries from users by saving the results in ram.

Our server had high traffic and 100% CPU processing – (Lynix server)

Fix:

  • SSH into server with putty etc.
  • backup my.cnf ( sudo cp .my.cnf .my.cnf_bak )
  • edit the config file ( nano .my.cnf )
  • add :
    query_cache_type = 1
    query_cache_size = 128M (or different values etc.)
  • Ctrl X, Y, enter (save/close)

Zeus Server Add or Remove www to domain URL Redirect

Working for a web development company for a short term contract job, Zeus is the bane of my life now:

add www

RULE_0_START:match IN:Host into $ with ^domain.com.au$if matched thenmatch URL into $ with ^/(.*)$    set OUT:Location = http://www.domain.com.au/$1    set OUT:Content-Type = text/html    set RESPONSE = 301    set BODY = Movedgoto ENDendifRULE_0_END:

remove www

RULE_0_START:match IN:Host into $ with ^www.domain.com.au$if matched thenmatch URL into $ with ^/(.*)$    set OUT:Location = http://domain.com.au/$1    set OUT:Content-Type = text/html    set RESPONSE = 301    set BODY = Movedgoto ENDendifRULE_0_END:

redirect domain 301

match URL into $ with (.*) if matched then    set Response = 301    set OUT:Location = http://www.secureyourdata.com.au$1    set OUT:Content-Type = text/html    set Body = Go <a href=”http://www.secureyourdata.com.au$1″>here</a> instead. endif

 

I need to rewrite URLs for SEO for a client, they better be able to change to an apache server, or I’ll move servers…

Ahh.. they changed servers…. why does Zeus exist? I spent about 3 or 4 hours trying to get rewrites to work…

Reset WordPress Admin password through FTP

Edit the “functions.php” file (wp-content -> themes -> name-of-current-theme -> functions.php

And add the following code to the beginning of it – before everything else:

<?php   
  wp_set_password('password',1);  
  $user_info = get_userdata(1);  
  echo 'Username: ' . $user_info->user_login . "\n";
?>

Then open your website, and it will show your 1st admin user’s username printed somewhere at the top of your website.

The password for that user account will now be “password”.

Delete the above code from “functions.php”, and login to your admin account, changing your password.

Resetting your password in Joomla

With Joomla, you aren’t that lucky… Joomla is slightly more secure, and quite the bit more annoying. They don’t provide a function to email yourself the password, so you need to edit the database. You can do the following

  1. Login to your MySQL Database using phpMyAdmin
  2. Go to your Joomla Users table, EG: jos_users
  3. Select the record (or table row) for your administrator account (The first admin account, created by default, has an id of 62)
  4. Click on ‘Edit Record’ or ‘Edit Inline’
  5. Select the drop-down “function” of “PASSWORD” on the right
  6. And add 5f4dcc3b5aa765d61d8327deb882cf99 as the new password
  7. Save
  8. Login to your site using the password “password” – site.com/administrator
  9. Then change your password when you login