WordPress.org

Ready to get started?Download WordPress

Forums

Replacing an existing function with a plugin? (3 posts)

  1. fireundubh
    Member
    Posted 7 years ago #

    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.

  2. Kafkaesqui

    Posted 7 years ago #

    "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:

    http://wordpress.org/support/topic/97070
    http://wordpress.org/support/topic/90258

  3. fireundubh
    Member
    Posted 7 years ago #

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

    See: http://www.igda-sandiego.org/

    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 . '">' ...

Topic Closed

This topic has been closed to new replies.

About this Topic