There are a number of wordpress plugins available today that would display some particular content at the bottom of your wordpress posts. These plugins could be anything ranging from subscription options for your blog, sharing links for the post OR a plugin to display related posts to the existing post. Once you enable the requisite plugins, you would see the various outputs appearing at the bottom of every post. As an example, for the post on call to action button, the following snapshot show the information displayed by the plugins just after the post ends.
As you would notice above, the last paragraph of the post ends with <You can always submit any useful tools, web services and tips to us.>. Just below this text, there is output provided by the following three plugins --
- Outbrain for showing visual( thumbnail ) related posts. ( Under <You might like:> )
- Sexy Bookmarks Plugin for displaying post sharing options. ( Under <Share This Post:>
- Yet another related posts plugin for displaying related posts as text URLs.( Under <Related posts:> )
While the plugins do their job, I was not happy with the order in which they appeared below the post content. Essentially I wanted the plugins to display in the following order.
The idea for this order was to club the plugins logically. To encourage the visitors to share the post, I wanted to have the sharing links immediately after the post content. This way the probability of a visitor using the links increases as opposed to having them after the Outbrain posts. Just after the sharing options, I wanted to have the Outbrain related posts to provide the visitor with a nice visual feel. At the end, I wanted to have the related posts as provided by the Yet another related posts plugin.
I had not specified any order of appearance for these plugins as such. This was the default output that I got after installing all these plugins. Now I had to figure out how to modify this order without too many changes. A little knowledge about wordpress php helped in this regard. Basically either of the plugins uses the add_filter hook to add content at the bottom of wordpress post. The syntax is as given below.
<?php add_filter( $tag, $function_to_add, $priority, $accepted_args ); ?>
The above syntax just says using the function <function_to_add>, update the content of <tag>. In our case, <tag> would contain the native post text content that has been written. The <function_to_add> function would specify what is to be added to the bottom of the post and would return the current content( i.e the native post text) concatenated with the further content as desired by the plugin ( eg if we assume that first add_filter is done by Sexy Bookmarks Plugin, then it will be the various post sharing animated image icons ). This returned final content would be treated as the current content for the subsequent call of add_filter i.e the current content in the next add_filter invocation would would be the final content returned by the previous add_filter which in this case would be the native text+sexy bookmark icons and hence anything else would be displayed below the sexy bookmarks plugin output. Each of these plugins would use the above add_filter to append their content to the existing post.
So to solve the problem, I started to explore the add_filter options. This is where the <priority> option details led to the solution
$priority (integer) (optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. Default: 10
So the idea was to use this priority to make the Sexy Bookmarks Plugin options appear first of all. For doing the same, I just searched for the add_filter inside the wp-content/sexybookmarks/ folder and found it to be available in wp-content/sexybookmarks/includes/public.php. I did a single line change as follows
add_filter('the_content', 'sexy_position_menu', 0);
As you would notice, I just specified a priority value of zero to make sure that the add_filter done by the Sexy Bookmarks Plugin is given priority and appears on top of the add_filter done by other plugins. With this simple change, the problem got resolved and the same snapshot appears as follows with the desired result.
The only downside is that I did this change in the plugin file for Sexy Bookmarks Plugin. So if I upgrade or replace this plugin tomorrow, then this change will no longer have a utility. The positive part is that as long as one is clear about the change and semantics of it, this should work well for a good time. If you have multiple plugins and want to specify the order explicitly, you might need to specify the above change in multiple files i.e add_filter for each plugin.
Do try this change yourself if you found it useful and share your feedback. If you think there are better and easy way to achieve the same result, do update us in the comments section. You can always submit any useful tools, web services and tips to us.