Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm new to wordpress, so chances are I'm missing something pretty basic here.

I'm trying to write a plugin which uses custom PHP code to generate output. I managed to get this working on the admin-side, but on the user side a properly working solution eludes me.

I've managed to find the following 2 hooks to use:

add_action ('parse_request', 'myPluginFunc');
add_action ('wp', 'myPluginFunc');

When I call index.php?MyPlugin=myPluginFunc this works in the sense that myPluginFunc() is called and it's output is echoed back on the screen, however the output is placed above the main theme output area (right below the top black WP menu bar).

So: How do I display output generated by a custom PHP function (output which is not a Post) on the main display area of the page? What hooks do I use to achieve this?

Any pointers would be much appreciated.

Greetings/Thanks Robert

share|improve this question
4  
Where exactly in the template do you want your Plugin content to be output? –  Chip Bennett Mar 8 '12 at 19:36
    
On my test/demo install, I have in vertical order: 1) Black WP menu bar (across width of entire window) 2) Site Title 3) Image 4) Black Content menu bar (across width of content area) 5a) Left/Main Content Block containing "Hello World" 5b) Right Content Block: Search, Recent Posts, Recent Comments, Archives, Categories, Meta I would like my content to be shown in 5a. Alternatively 5a and 5b combined would also be OK. Thanks Robert –  user13955 Mar 8 '12 at 22:36

1 Answer 1

The two most common ways to add in such Plugin output directly into the template are:

  1. Use a Theme-provided action hook
  2. Instruct the user to add a Plugin function call manually into the template

Some, though not many, Themes provide custom action hooks in the template, that you could use to output your Plugin content.

For example, in my Oenology Theme, I have a oenology_hook_loop_before action hook, that you could use, like so, within your Plugin:

<?php
function wpse44952_add_loop_before_hook() {
    myPluginFunc();
}
// Hook into Oenology template
add_action( 'oenology_hook_loop_before', 'wpse44952_add_loop_before_hook' );
?>

Note, though, that such hooks aren't standardized. Any Theme that provides such hooks will use its own naming convention. So, you'd have to add add_action() calls for every such Theme that you want to support.

The other common method is simply to ask users to add myPluginFunc() manually into the template, wherever it needs to be output. While sub-optimal, end users are also fairly used to doing this with other Plugins (e.g. WP PageNavi).

share|improve this answer
    
Thank you very much of your explanation; I'll be trying this over he weekend. For what it's worth, I've in the meantime gotten a variant of this to work which uses a shortcode which is inserted into an automatically generated post. –  user13955 Mar 9 '12 at 10:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.