Support » Plugins » targeting plugin actions

  • Targeting

    Hi, I’m writing a simple plug-in that includes info on every entry.(eg like the postmetadata)

    Problem is: – without adding a custom hook to the template, how can I tell the plug-in where to add my code?

    – I want it to add info immediately after the_content(); or similar (eg. postmetadata)

    – Is there a way to target specific areas?

    I’ve tried this:

    add_action('the_content' , 'myFunction');

    But this replaces the whole content, not append it.

    I need your help.


    MAC 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need a filter, not an action hook. If you filter on the_content, you should be able to append your data to it.

    The other alternative is a shortcode. Add that into your template and have the shortcode handler return the data you want inserted in place of the shortcode.

    A filter is probably the best bet though.

    Hi willkemp

    I had tried the filter and the result was roughly the same.

    But I understand that a filter is more adequate since I’m not depending on any event to trigger my plug-in functions (other then the loop).

    For now I’ve managed to do it by using a filter and hooking it to the “comments template”

    add_filter('comments_template' , 'myFunctuion');

    But I’m not satisfied. It does what I want but I’m now fully aware of the costs, I’ve tested it and so far so good, but it seems a bit dodgy…

    Shortcodes I’ve never used. I’ve surface-read something about them, but I guess I will eventually have to start reading something deeper about it.

    But for this case I really want the plug-in to be Universal (or closely) regardless of the template used, so I didn’t want to add anything to the template, and hook it to a “default” content location.

    Thanks for your help! I will continue digging it till I’m satisfied.

    MAC 🙂

    In your the_content filter handler, are you returning the calling parameter with your extra content appended to it? It sounds like you’re just returning your extra content, rather than appending it to the content the handler’s called with.

    Even if it works with the comments, it seems logically wrong to use that to effectively add something to the_content. And if it’s logically wrong, there’s a chance that it will cause you problems in the future.

    Willenkemp you’re absolutely right.

    The problem is I am in fact replacing the content and not appending it, as I should. Thing is, I don’t know how to do it 🙂

    Can you help?

    MAC 🙂

    To append a string to a string variable in php, you use the ‘.’ notation.


    $string .= $newString;

    (the contents of $newString will be appended to the contents of $string).


    $string = $string.$newString;


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘targeting plugin actions’ is closed to new replies.