Support » Plugins » Replacing an existing function with a plugin?

  • How do you replace an existing function with a plugin?

    For example, I’d like to create a plugin that modifies _page_level_out() to clean page titles of HTML elements, so that when I upgrade, I don’t have to hack the source again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • How do you replace an existing function with a plugin?

    Except in the case of a few (what are called “pluggable”) functions, you cannot. At least, not in the way you’re looking to accomplish it.

    What you could do is recreate the function in your plugin by renaming it, make the modifications to it you require, then call your function instead of the original in your templates. In the case of wp_list_pages(), this would require copying (and renaming) a number of functions that would have to be modified to call the new functions, etc. But it can be done.

    Another option available to you with wp_list_pages() is to do the HTML *cleaning* in your template. You can do this by setting the echo parameter to 0 (false), and assigning what is returned to a variable:

    <?php $my_pages = wp_list_pages('echo=0'); ?>

    From there you can parse the Page title from each link and do whatever you need to with them, then echo (display) the results. Though they don’t cover duplicate issues, here are a few threads dealing with similar solutions:

    I tried cleaning the HTML elements using the in-the-template method you described, but I don’t think that works.


    The bold sidebar menu items are pages with <strong>titles</strong>.

    When I try to clean the template directly…

    $sidebarMenu = wp_list_pages('sort_column=menu_order&title_li=');
    echo strip_tags($sidebarMenu);

    …the formatting is lost.

    To retain the formatting, I modified template-functions-post.php like so:

    $title = $cur_page['title'];
    // $title = wp_specialchars($cur_page['title']);

    $output .= ... title="' . strip_tags($title) . '">' ...
    // $output .= ... title="' . $title . '">' ...

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replacing an existing function with a plugin?’ is closed to new replies.