Need a WordPress website this weekend? Start here...

DIY WordPress: Really Simple Plugin Admin Menus

(Reading time: 3 – 4 minutes)

Following our Technical Tuesday theme, here’s another stupendously popular WordPress Plugin mini-tutorial.

This tutorial shows how to create menu and submenu items in your left sidebar in the WordPress administration interface.

Here’s what it looks like:
Admin Menu WordPress Administration page

The blue arrow points to a spiffy menu icon, the orange highlighting to the menu title, and the green highlighting to the submenus. The name of the plugin is “Demo Admin Menu.”

First, let’s examine the structure of the the plugin.

WordPress Plugin Structure

This following listing is a pseudo-code. It looks like PHP but it’s not. It’s like PHP with all the confusing syntactical parts stripped out, and simplified functions. As you can see, all that’s left is the structure of the code, which is exactly what we want:

class demo_plugin_adminmenu {

    function demo_plugin_adminmenu() {
        add_action(admin_menu, add_demo_menu)
    }

    function add_demo_menu() {
        add_menu_page( call demo_menu_page)
        add_submenu_page( call demo_submenu_page')
    }

    function demo_menu_page() { write a web page }
    function demo_submenu_page() { write a web page }
}

Each function listed in the pseudo-code above may have one number or more arguments. The Codex documents the WordPress functions add_action, add_menu_page and add_submenu_page.

Part of the reason for this article is that the Codex doesn’t document the exact syntax for these calls, which depends on the context in which these calls are made. If the calls are made outside of a class, use the Codex version directly. If made within a class, as shown here, the callbacks will need to be wrapped as shown in the code listing next.

WordPress Admin Menu Plugin

Here’s the final code listing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
 
 
if (!class_exists("demo_plugin_adminmenu")) {
 
    class demo_plugin_adminmenu {
 
        function demo_plugin_adminmenu() {
            add_action('admin_menu', array(&$this, 'add_demo_menu'));
        }
 
 
        function add_demo_menu() {
            if (function_exists('add_menu_page')) {
 
                add_menu_page('Menu Page Title', 'Menu Title', 
				              'administrator', __FILE__, 
							  array(&$this, 'demo_menu_page'), 
							  WP_PLUGIN_URL.'/demo-plugin-adminmenu/award_star_gold_1.ico');
 
                add_submenu_page(__FILE__, 'Page Title', 'Submenu Title', 
				              'administrator', 'submenu_handle', 
							  array(&$this, 'demo_submenu_page'));
            }
        }
 
        function demo_menu_page() {    
			?>
			<div class="wrap">
			    <h2>Demo Menu Page</h2>
			    Does nothing but demonstrate menu.
			</div>
			<?php 
        }
 
        function demo_submenu_page() {
			?>
			<div class="wrap">
			    <h2>Demo Submenu Page</h2>
			    Does nothing but demonstrate submenu. 
			</div>
			<?php 
        }
    }
}
 
$wpdpd = new demo_plugin_adminmenu();
 
?>

You could copy and paste this code listing. But you would learn it better if you typed in by hand, which is what often do. Don’t forget to add the plugin header information.

WordPress Plugin Tutorials

These mini-tutorials are designed to provide a single lesson resulting in runnable code, with no extras.

Each provides a simple, standalone plugin. You can use these plugins like bricks, combining to create your own plugins.

Often, these tutorials go beyond the WordPress Codex to demonstrate new techniques which aren’t documented in the Codex.

Fast Process For Fixing Image SEO In WordPress

(Reading time: 3 – 4 minutes)

Nightmare! You have just learned that you’re doing your blog post images all wrong!


You’re not getting any SEO goodness from your images, and missing out on potential traffic.

Bummer!

If you just dropped into this ongoing series of articles on SEO and WordPress images, check out both “Advanced SEO IMG Element Handling For WordPress (Part I)” and “Advanced SEO IMG Element Handling For WordPress (Part II).” These articles give the knowledge for why you need to deal with image SEO on your WordPress blog, and a pretty good peek “under the carpet” for what it all means.

But if you don’t care about all that and just want to get straight to the good stuff, follow these directions carefully to help you get better search engine results from having embedded images.

Reaping SEO benefits from images

When you’re adding new images to an article, just make sure to add in all the metadata correctly before inserting the image into the article as shown in “Advanced SEO IMG Element Handling For WordPress (Part I)“.

It’s harder if you have already published the image. You have to make a decision:

  1. Fix only the <img> alt and title attributes in your article. This is probably the fastest way to proceed, but you won’t have the metadata in your Media Lirbary if you want to use the image in a future article.
  2. Fix the img attributes in your blog’s Media Library and reinsert each fixed image. This is the most accurate way, but it’s also the most time consuming.
  3. Use copy-paste to add the same text to both the img attributes in the web page source and in the media library. This splits the difference between the first two methods. You will have to have a couple of windows open, but it’s reasonably fast and reasonably accurate.

For images, you want to break this down into repeatable tasks so you don’t have to do it all at once.

I use Juicy Studio Img Analyzer to examine all the images on the page. The first time you run this tool, it can be overwhelming to see all the warnings and errors. But it’s worth spending a couple of hours analyzing your blog to see where potential problems could be.

Here’s a few suggestions for getting started:

  1. Knock out the front page first.
  2. Fix the <img> element in the top post first.
  3. Check search results for hot posts.
  4. Choose a random post that you like, with a fun image, fix that one.
  5. Wash, rinse, repeat over time as hot search terms evolve.
  6. Make sure to handle images correctly going forward.
  7. Keep track of posts with images that have been fixed.

If you’ve been blogging a while, and have loads of images without metadata, you’re not going to be able to fix them all at once. Just take your time and fix the most important, and make sure you get those alt and title attributes written correctly going forward.