The selector’s doing most of the work here - looking for anchors linking to absolute URLs, and then basically filtering out anchors with absolute URLs pointing to the current document’s domain. When the outgoing links are clicked, we fire off the event tracking method in Google Analytics. This clicks will be categorized as “Outbound Links” and the anchor’s full URL will be tracked as an Action.
I’ve been working on a site recently that’s needed a lot of pseudo sprites, and I was getting frustrated with creating sprite maps by hand, so I created simple Photoshop plugin that takes a directory of images and merges them into a CSS friendly sprite map.
While working on the new theme for the site, I quickly realized that I didn’t want to show pages in any of the searches on the site. I only wanted posts.
It was easy enough to find articles that illustrated ways to exclude certain categories or posts by ID, so I decided to apply those methods to pages as well. Simply paste the following into your theme’s functions.php file.
123456789
function gdmExcludePagesInSearch($query) { if ($query->is_search) { $query->query_vars['post__not_in'] = get_all_page_ids(); } return $query;}add_filter('pre_get_posts', 'gdmExcludePagesInSearch');
This will remove all pages from the loop, and only on the search page.
Something unclear, or have something to add? Please leave a comment.
I’ve been working on a little WordPress project these last few weeks with a colleague. When I first heard the idea, I thought, “That should be easy enough to build.” I decided the best way to tackle the feature would be a custom widget, but when I finally sat down to get it working I quickly began to realize that there were a few obstacles to overcome.
The project was really meant to extend an existing widget, and it seemed confusing to have both the default and extended version there side by side (plus it would be really nice to call them the same thing for transparency). I needed to get rid of it. You can’t just overwrite an existing widget by registering a new one by the same name - WordPress ignores it. And if I did manage to find a way to remove a default widget, when do you have to do it?
Luckily, some digging around found a solution.
12345678910
function gdm_widget_meta_register() { // unregister the widget and its control wp_unregister_sidebar_widget('meta'); // register the new and improved widget and control wp_register_sidebar_widget('meta', __('Meta'), 'gdm_widget_meta'); wp_register_widget_control('meta', __('Meta'), 'gdm_widget_meta_control');}add_action('widgets_init', 'gdm_widget_meta_register', 1);
The really important pieces are the wp_unregister_sidebar_widget function and the widgets_init action hook. widgets_init actions are run right after all the default widgets are registered, giving us the perfect opportunity to call wp_unregister_sidebar_widget with the ID of the widget you’re getting rid of. Now you can register your own widget and control, effectively replacing a default WordPress widget.
I received an email this evening from Dan, who uses the Page Link Manager, wondering how to get a home page link to show up in his site navigation. I had never really thought about the problem, or even realized it was a problem until I started my search for a solution. There’s not much out there covering the issue besides a few forum posts at WordPress.org. But it’s a problem, nevertheless. I understand that the blog’s heading is supposed to link to your home page, but I believe there’s a large audience of Internet users, and potential readers, that wouldn’t think to look to a heading for a shortcut back to your home page.
And so we have the Home Page Link plugin.
The Plugin
The plugin does just what you think - adds a Home link to your site navigation (wp_list_pages). And it’s very easy to use.
Place the plugin file under wp-content/plugins directory on your Wordpress Installation
Log in to your admin interface and activate Home Page Link under the ‘Plugins’ tab
That’s it! You should now be able to view your site with its shiny new Home link.
Like my other plugins, I hope to keep this going as a work in progress, and work along with the WordPress community to make it more useful and efficient. If you have something you’d like to see in an upcoming version, please don’t hesitate to add a comment or contact me.
Requirements
The current release requires a server running at least PHP4. The plugin has been tested on Wordpress 2.x. If anyone has gotten it working on older versions of Wordpress, please let me know.
I can’t really call this a new plugin. If you look under the hood, most of codebase is just a reworking of the popular Page Link Manager. It’s one of the nice things about Wordpress plugin development – being able to borrow ideas from similiar plugins – and it’s what makes scripting for Wordpress enjoyable.
The motivation behind this plugin is the fact that excluding categories is somewhat of a barrier to those of us who are not programmers. It used to be that we would have to dig through PHP templates and add exclude=2,7 to the wp_list_cats tag. To clients or anyone not familiar with the Wordpress system, that may seem like an impossible task. And, for those who are comfortable with the Wordpress system, it can be just plain annoying. The Category Link Manager attempts to make things just a little bit easier.
The Plugin
The Category Link Manager Plugin is a Wordpress plugin that adds an administration panel that allows users to pick which category links are included in the site navigation. It also provides a function that uses these settings to replace wp_list_cats. Adding it to your Wordpress installation is as easy as ever.
Place the plugin file under wp-content/plugins directory on your Wordpress Installation
Log in to your admin interface and activate Category Link Manager under the ‘Plugins’ tab
Go to the new panel under the ‘Manage’ tab called ‘Category Links’
Select and update the categories you want included in your site navigation
Open the source of the template file where you call the wp_list_cats function (the default file is sidebar.php, however it may be different if you’re using certain plugins) and replace it with gdm_list_selected_cats.
If you’re wondering, gdm_list_selected_cats is what does all the work for us. It takes the categories we chose to include in the navigation and works out what categories it should exclude. Besides that, it acts exactly like wp_list_cats – it even takes the same parameters.
Here’s a few examples of what we can do:
123456789
// sort the categories by namegdm_list_selected_cats('sort_column=name');// sort the list by name and show empty categoriesgdm_list_selected_cats('sort_column=name&hide_empty=0');// sort the list by name and manually exclude // additional categoriesgdm_list_selected_cats('sort_column=name&exclude=2,7');
Like my other Wordpress plugins, I hope to keep this plugin going as a work in progress as it helps make content management just a little bit easier. If you have any problems, questions or suggestions, please let me know.
Requirements
The current release requires a server running at least PHP4. The plugin has been tested on Wordpress 2.x. If anyone has gotten it working on older versions of Wordpress, please let me know.
WordPress is a fantastic tool – I can’t say that enough. I was able to migrate my old site and structure over to the WordPress model quite quickly, and in a matter of minutes I was blogging. But one of the major hurdles is that it still relies on coding knowledge a bit. For example, under the current version of WordPress, to exclude a pages from site navigation, you have to go into the source and do something like wp_list_pages('exclude=3,7'). And, if you add other pages you don’t want listed in the site navigation, you have to go into and edit the source each time. This became an obstacle recently when my sister and I began looking at WordPress as a viable content management system for clients’ use. It seemed silly to us that each time the client wanted to include an excluded page or exclude a new page they’d have to call on us, or we’d have to teach them some elementary programming skills. And so the Page Link Manager Plugin was created.
The Plugin
The Page Link Manager Plugin (I know it’s a mouthful) is a WordPress plugin that adds an administration panel that allows users to pick which page links are included in the site navigation. Adding it to your WordPress installation is as easy as ever.
Place the plugin file under wp-content/plugins directory on your Wordpress Installation
Log in to your admin interface and activate Page Link Manager under the ‘Plugins’ tab
Go to the new panel under the ‘Tools’ tab called ‘Page Links’. If you use widgets, you can access page link settings through the Page widget
Select and update the pages you want included in your site navigation.
Here’s a few uses of the wp_list_pages function:
123456789
// add a heading to the page link listwp_list_pages('title_li=<h2>Pages</h2>');// sort list by the menu orderwp_list_pages('title_li=&sort_column=menu_order');// add a heading to the page link list and // exclude a couple extra pageswp_list_pages('title_li=<h2>Pages</h2>&exclude=4,7');
Take a look at that last example again. Can we just manually exclude pages that way even if the function’s loading pre-defined excluded pages? Of course we can. The function’s designed to look for and deal with manual page exclusions.
I hope to keep this plugin going as a work in progress as it helps make content management just a little bit easier. If you have any problems, questions or suggestions, please let me know.
Requirements
The current release requires a server running at least PHP4. The plugin has been tested on Wordpress 2.5+. If anyone has gotten it working on older versions of WordPress, please let me know.