[resolved] Add custom hook(filter and action) (3 posts)

  1. Amit Sukapure
    Posted 1 year ago #

    Hello All,

    How to add custom hook in WordPress?
    Here what I've tried before,

    # add action in functions.php

    add_action('my_logo', 'my_logo');

    function my_logo($logo)
    	echo $logo;

    # do action in template file

    $logo = '<img src="PATH"/>';
    do_action('my_logo', $logo);

    Now I want my logo wrapped by adding filter to my_logo,

    add_filter('my_logo', 'modified_logo');

    function modified_logo($logo)
    	$logo = '<span>'.$logo.'</span>';
    	return $logo;

    But not getting expected result.
    Any help appreciated.

  2. Steven Gliebe
    Posted 1 year ago #

    add_filter() won't do anything without apply_filters() being implemented: http://codex.wordpress.org/Function_Reference/apply_filters

  3. Amit Sukapure
    Posted 1 year ago #

    Yes, I found that solution by playing with hooks for couple of hours.

Topic Closed

This topic has been closed to new replies.

About this Topic