WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To Override a Command In a Parent Theme's Functions.php File (3 posts)

  1. GreenGriot
    Member
    Posted 1 year ago #

    I'm trying to figure out the right syntax for overriding a command in a parent functions file from within the child theme's functions.php.

    I'm currently using a child theme of Minimatica which ran into an issue with its file uploader after the last upgrade as discussed here:
    http://wordpress.org/support/topic/issues-with-35?replies=17

    Daniel, the Theme Author provided a new solution which does work but it requires replacing 2 lines in the functions.php file as described here:
    http://www.onedesigns.com/support/topic/how-to-fix-issues-with-media-uploader-with-minimatica-in-wordpress-3-5.

    Replacing these lines in the original functions file works but I know it is only temporary until the next update. However, I can't seem to get this to work from the child theme's function file.
    My child function's file was empty except for the two new lines (Wrapped in php code of course.)

    <script src="http://pastebin.com/embed_js.php?i=YYGk8F7d"></script>

    Not sure what I'm doing wrong.

    Any Help would be appreciated.

    Cheers!

    jmw

  2. GreenGriot
    Member
    Posted 1 year ago #

    Hi All,

    Found the answer in a previous post:

    http://wordpress.org/support/topic/problem-redeclaring-funtion-in-functionsphp-in-a-child-theme?replies=7

    The answer seems to be to use the "add_" and "remove_" function references (or "hooks") in the child 'functions.php' file.
    In this case the "add_filter"/"remove_filter" and "add_action"/"remove_action"

    When I added the following code to the functions.php of my child theme the override worked perfectly.

    <?php
    
    //code to override theme function in parent theme in order to fix Image loader problem after 3.5 update
    
    add_action('wp_enqueue_scripts', 'minimatica_register_styles');
    add_filter( 'ext2type', 'minimatica_file_types' );
    
    remove_action('init', 'minimatica_register_styles');
    remove_filter( 'ext2type', 'minimatica_mime_types' );
    
    //

    http://pastebin.com/gFFhsWbr

    You'll find more info about these functions here in the codex:
    http://codex.wordpress.org/Function_Reference/remove_filter

    http://codex.wordpress.org/Function_Reference/add_filter

  3. GreenGriot
    Member
    Posted 1 year ago #

    Hope This Helps.
    Cheers!

    jmw

Topic Closed

This topic has been closed to new replies.

About this Topic