WordPress.org

Support

Support » How-To and Troubleshooting » How to Make My Own Theme Hooks / Plug-Able Features?

How to Make My Own Theme Hooks / Plug-Able Features?

  • Leo Blanchette

    @leoclipartillustrationcom

    How do you make a system that searches user functions at a given point?

    add_my_theme_action('my_special_theme_area', 'my_function');
    
    function function(){
    }

    Gonna start selling plugins for my theme and I thought this might be something worth doing right, so other people can do the same.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can run your own actions using the do_action() function. Just be sure to use it in a place where all of the functions can be registered before it’s called.

    Leo Blanchette

    @leoclipartillustrationcom

    So there must be a do-action hook thingy I can place, say, at the end of my product price table? And call it something like “product_table_bottom” and it will fire right there?

    Yes, that’s right.

    Leo Blanchette

    @leoclipartillustrationcom

    Not that I lack motivation – I only post here as a last resort, but I am not seeing info on this, its sort of unclear how to achieve what I’m setting out to do here… http://codex.wordpress.org/Function_Reference/do_action

    Lets suppose I want to place some hook or action within some area on my custom post type page.

    What function or method “anchors” user defined functions to a given area?

    Exactly what I posted above. 🙂 Don’t worry, it can be a bit ahrd ot get your head around when you first look at it.

    Setting up your hook:

    function do_my_hook() {
        echo "<p>Output something here</p>";
    }
    
    add_action ("my_hook', "do_my_hook");

    Running your hook action in your template file:

    <?php
        do_action ("my_hook");
    ?>

    You can call the action anything that you want – as long as it doesn’t interfere with any existing action names.

    Leo Blanchette

    @leoclipartillustrationcom

    Oh – it is easy. It was so easy it was hard to figure out because I expected it not to be easy. Thanks for helping 😀

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to Make My Own Theme Hooks / Plug-Able Features?’ is closed to new replies.
Skip to toolbar