WordPress.org

Ready to get started?Download WordPress

Forums

How to Make My Own Theme Hooks / Plug-Able Features? (7 posts)

  1. Leo Blanchette
    Member
    Posted 1 year ago #

    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.

  2. catacaustic
    Member
    Posted 1 year ago #

    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.

  3. Leo Blanchette
    Member
    Posted 1 year ago #

    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?

  4. catacaustic
    Member
    Posted 1 year ago #

    Yes, that's right.

  5. Leo Blanchette
    Member
    Posted 1 year ago #

    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?

  6. catacaustic
    Member
    Posted 1 year ago #

    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.

  7. Leo Blanchette
    Member
    Posted 1 year ago #

    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 :D

Topic Closed

This topic has been closed to new replies.

About this Topic