The Site Tree's Action Hooks

Whenever the Site Tree is rebuilt, there are four Action Hooks that are triggered:

Adding Content to the Site Tree

The code below places a paragraph on top of a list of books. A 'Book' Post Type can be added to a WordPress website via the Custom Post Type functionality.

function insert_paragraph_before_book_list( $siteTreeBuilder ) {
    if ( $siteTreeBuilder->listID() == 'book' )
        $siteTreeBuilder->addContent( '<p>A paragraph on the listed books.</p>' );
}

add_action( 'sitetree_will_build_single_list', 'insert_paragraph_before_book_list' );

The $siteTreeBuilder parameter is a reference to the object of class SiteTreeBuilder to which is assigned the task of building the Site Tree. Its class' interface, declared in core/builders/builders-interfaces.php, is the following:

interface SiteTreeBuilderInterface {
    /**
     * For a paginated Site Tree, returns the number of the page
     * that is being built.
     *
     * Only available in SiteTree Pro.
     *
     * @since 2.0
     * @return int
     */
    public function pageNumber();

    /**
     * Returns the unique identifier of the list that is being built.
     * For Custom Post Types, it coincides with the Post Type Key.
     *
     * @since 1.0
     * @return string      
     */
    public function listID();
    
    /**
     * @since 1.0
     * @param string $string      
     */
    public function addContent( $string );
}
Last update: