WordPress only show content for logged in admin user

Sometimes one might only want to show some content for logged in admin users, or a specific admin user – for testing purposes etc.

you can use this code:

$current_user = wp_get_current_user();
if($current_user->user_email == "email@address.co")
  function(); // this function will only happen when this one admin user is logged in.
<p>This HTML will only show when the user is logged in</p>

For content to be shown when a user is logged in as an admin in general, this can be used:

<?php if ( is_user_logged_in() ) {
  echo "This will be shown if a user is logged into the admin section.";
} ?> 

Various JavaScript Programming Notes

To make a 2 dimensional array

var v=new Array();
var v2=new Array();
v[0]=1; v[1]=7; v2[0]=v;
var x = v2[0][0] // x is 1;

Add to an array


Function – If string S is in array A, then return true

function inArray(string, array){
 for(var i = 0;i < array.length;i++){
 if (array[i]==string){
 return true;
 return false;



Featured Video rather than Image for WordPress

Some templates have a featured image, but sometimes you want a video instead… But not all the time..

You can set some custom fields, and then add in PHP – if the field has something in it – display the embedded video (at the same size the featured image would have been…)

The text in the custom field should just be the ID code for YouTube or Vimeo (or you can add your own if you want… but you need to add the embed code to the PHP)

The code gets the ID and inserts it into the embed code.

if (post_custom(‘a YouTube ID Code’)) {
echo ‘<iframe width=”640″ height=”402″ src=”http://www.youtube.com/embed/’ . get_post_meta($post->ID, ‘a YouTube ID Code’, $single = true) . ‘” frameborder=”0″ allowfullscreen></iframe>’ ;
else if (post_custom(‘a Vimeo ID Code’)){
echo ‘<iframe src=”http://player.vimeo.com/video/’ . get_post_meta($post->ID, ‘a Vimeo ID Code’, $single = true) . ‘?title=0&amp;byline=0&amp;portrait=0″ width=”400″ height=”225″ frameborder=”0″ webkitAllowFullScreen allowFullScreen></iframe>’ ;


add the YouTube or Vimeo ID code to a custom field:

  • a YouTube ID Code
  • a Vimeo ID Code


  • bH9tJXm2Bcw
  • 31934775

From the original YouTube links:

  • http://www.youtube.com/watch?=bH9tJXm2Bcw&feature=channel_video_title
  • http://vimeo.com/31934775

Add custom fields to posts and pages

Just to quickly add info to a page

enable custom fields with the dropdown

then add this code:

echo get_post_meta(get_the_ID(), ‘your-name-of-custom-field’,  true);

Shift Joomla and WordPress installs

  • Copy HTML/CSS/etc. – folders. everything
  • Move the database

Login to old cPanel -> PHPmyAdmin
select databse, check all tables, “export” – all (custom – all options)

Go into new PHPmyAdmin
import all

edit (WP-config.php,. config.php (in Joomla)

Edit the database location:

  • Databse name (same)
    But – might be something like:
    old DBS name is “shop”
    new name is “rotapixt_shop”
  • Server (local host if it is on the same server, else the address (EG: http://cpanel.something.com)
    it’s possible to install the HTML files on one FTP account server, and install the database on a different server….
  • Database user username:  (hosting account username/ password login)
  • Database user password

In website hosting – you have an account username and password, this is the same for :

  • FTP account
  • cPanel login (maybe PHPmyadmin has a different password)
  • Database / MySQL username / password (would be the same as PHPmyAdmin)

Joomla – Configuration.php:

  • host $host
  • DB name $db
  • username MYSQL $user
  • pass $password

WordPress – wp-config.php

  • commented with labels ~


HTML goes in the htdocs folder

http://localhost/cpanel(then click “PHPMYADMIN” to edit database

  • DBS name = whatever you call it in PHPmyadmin
  • server = localhost
  • username = root
  • password = “” (nothing)

My default WordPress Settings

I always set this stuff up like this:
  • General
    • Site title/tagline
  • Writing
    • Default Post category – change name from default to (something with relevant keywords in it)
      Edit this in Posts->Categories
  • Reading
    • Front page displays “static page”
      • Create 2 new blank pages called  “home” and “blog” – set these two ~
  • Discussion
    • Disable the 2 emailers when people comment
  • Permalinks
    • Custom
      • /%category%/%postname%/

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?

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

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>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
<?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
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.

function custom_admin_css() {
echo '
<style type="text/css">
add_action('admin_head', 'custom_admin_css');

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> ?></li>
<?php endwhile;

<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.

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:

  $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