• Resolved robertosalemi

    (@robertosalemi)


    Good Morning!

    I would like to figure out how I can edit, via the functions.php of my ChilTheme, the HTML code generated by a function of the thema.

    I have this code:

    function crumina_social_icons()
    {
        global $one_touch_option;
    
        if (!$one_touch_option['expand_social_icons']){
            $class="closed";
        } else {
            $class="opened";
        }
    	if ($one_touch_option['soc_ico_panel']) :
    
        echo '
        <div class="row"><div class="large-12 columns">
        <div id="panel">
    
            <a id="open-social-button" href="#">
                <i class="linecon-globe"></i>
                <span class="desc">' . __('Pagine SOCIAL', 'crum') . '</span>
                <span>' . __('GDP', 'crum') . '</span>
            </a>
            <div id="soc-icons-wrap" class="' . $class . '">';
    
                crum_social_networks();
    
            echo '</div>
        </div>
        </div></div>';
    
    	endif;
    }
    
    add_action('reactor_header_after', 'crumina_social_icons', 2);

    I was trying to create a function like:
    add_filter('reactor_header_after', 'crumina_social_icons_custom');
    to replace the text “Pages SOCIAL” or other …

    How should I proceed?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • you cant filter an action..

    you need to remove the action and replace it with your own so something like this…

    <?php 
    
    // Deregister original function and register replacement
    function switch_crumina_social_icons()
    {
    	remove_action('reactor_header_after', 'crumina_social_icons', 2);
    	add_action('reactor_header_after', 'my_crumina_social_icons', 2);
    }
    add_action('after_setup_theme', 'switch_crumina_social_icons');
    
    /* NB. this is tricky but this action need to hook after the function
     * is original registered but before it is executed otherwise it will miss it.
     * 'after_setup_theme' should be about right.
     */
    
    // Replacement function
    function my_crumina_social_icons()
    {
    	# copy original code... here
    	....
    	# change as required.
    }
    
    ?>

    Thread Starter robertosalemi

    (@robertosalemi)

    Hi geraintp,
    thanks for your support, but this solution doesn’t work.

    If you see this screenshot, this hook generates a duplicate where the first row is created by the new functions and the second from the default.

    Maybe I must change ‘reactor_header_after’ with another $hook?

    Thanks.

    Hi ok,

    basically were hooking in too early, so the initial action hasn’t been added before we’ve tried to replace it.

    http://codex.wordpress.org/Plugin_API/Action_Reference

    try changing

    add_action('after_setup_theme', 'switch_crumina_social_icons');

    to

    add_action('init', 'switch_crumina_social_icons');
    
    or
    
    add_action('wp_loaded', 'switch_crumina_social_icons');

    Thread Starter robertosalemi

    (@robertosalemi)

    Hi geraintp,
    I resolved with your solution:

    function switch_crumina_social_icons()
    {
    	remove_action('reactor_header_after', 'crumina_social_icons', 2);
    	add_action('reactor_header_after', 'my_crumina_social_icons', 2);
    }
    add_action('init', 'switch_crumina_social_icons');

    Thanks for your support!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Override HTML output from a function’ is closed to new replies.