Here’s a macro plugin for WordPress I made. It features useful features for advertising, e.g. limiting the maximum amount of displayed ads.
What are macros?
A macro is a bit of text inside a post that, when displayed, will be substituted with other text. It simplifies editing of post and also provides a convenient way to insert repeating content.
Macros are useful for various uses:
- Adding common content shared by multiple posts/pages
- Post headers, footers and navigation between a series of posts
- License disclaimers
- Advertising inside post content (much more effective than leaving the ads outside the content)
- Simplifying complex layout by hiding unnecessary formatting, e.g. adding an image with a caption using only a short macro
- Quickly changing information on multiple pages, e.g. disclaimers, important notifications
- Configurable via the WordPress control panel system
- Automatically limits the number of injected macros (useful for e.g. Adsense whose TOS states you can only have three instances per page)
- Can be extensively controlled depending of page type (archive page, home page, single post etc.)
How it works
The macros are used by inserting text inside HTML comments when writing the post. Below is an example of a macro:
The macro looks like the above code when editing the post but when viewing the post (or page) it will be substituted with a Google Adsense advert (given that you have defined the macro).
Parameters can be used inside macros as follows. The first example is the text inside a post and the second is the macro defined on the Macross options page (with the name “image_with_caption”).
<--image_with_caption "image.jpg" "A photo I took last summer"-->
<p><img src="$1" alt="$2" /><br/>$2</p>
This macro will insert the text “A photo I took last summer” as the alt attribute for the tag and add it as a caption below the image.
You can use macros in a page template by using the expand_macro($name,$echo=true) function. This will also increment the counters. Here is the above example reinterpreted using expand_macro:
<?php expand_macro('image "image.jpg" "A photo I took last summer"'); ?>
By cleverly using macro priority (a lower priority macro gets injected first) you can use macros inside other macros. In combination with macro display options (i.e. if the macro is enabled for content, excerpts or feeds) you can use the same macro to expand into different text depending on where it is used.
Installation and configuration
Unzip the contents of macross.zip in your WordPress plugin directory and activate the plugin from Options > Plugins. Go to Options > Macross to create a macros. Counters work so that each successive macro injection increments the counter. If any of the specified counters for a macro exceeds the maximum value, the macro simply will not epand (also, none of the counters will be incremented).
The checkboxes next to a macro specify on which pages the macro will work. The first colum (Hook) tells Macross whether to expand the macro when actions the_content() or the_excerpt() is called. The third option enables the macro for the expand_macro() function. The rest of the checkboxes specify a page type, as returned by is_page(), is_single() and other conditional WordPress tags.
Yes, the following is done with a macro, too. ;)
- Another macro plugin Originally, I wanted to use this, but found it cumbersome to edit macros. Also, it doesn’t have a counter/limiter system