• Hi all,
    I am adding a sidebar into the single-post view of the Kubrik theme (done successfully) and I would like to create a custom action / filter tag that the theme would pick up on the sidebar I’ve created. From what I’ve read of the WordPress source code it should be a case of simply adding the filter via a plugin, then calling the filter-functions by using the “do_action” function.
    So far I have:

    \wp-content\themes\default\sidebar2.php

    <div id="sidebar">
    <ul><li>test include sidebar</li>
    <li><?php do_action('single_sidebar'); ?>
    </ul>
    </div>

    And a plugin to test the action:
    \wp-content\plugins\single-sidebar\single-sidebar.php

    <?php
    /*
    Plugin Name: Sidebar 2 Hook Test
    Plugin URI: https://www.tamingentertainment.co.uk/
    Description: test plugin
    Version: 1.0
    Author: Toby Berriman
    Author URI: https://www.tamingentertainment.co.uk/
    
    Copyright 2008 Toby Berriman
    Released under the terms of the GNU GPL v2
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    */
    
    function ss2() {
    	$content = '<p><em>Test action worked!!!</em></p>';
    	echo $content;
    }
    
    function remove_ss2() {
     remove_action('single_sidebar', 'ss2');
    }
    
      add_action('single_sidebar', 'ss2);
       register_deactivation_hook( __FILE__, 'remove_ss2' );
    ?>

    Unfortunately although the plugin activates successfully I am not getting the extra text on the sidebar that I expected ??

    Before anyone asks, the reason I want the custom action/filter is so that I can easily move plugin content that is applied to ‘the_content’ into the sidebar ??

    Any ideas / suggestion?
    ~Shiv

  • The topic ‘Trying to create custom actions / filters – help needed!’ is closed to new replies.