• I’m having a little trouble decided how I should be implementing hooks in wordpress.

    This is my problem,

    I’m currently using a child theme and in the single.php file of the parent theme there is a function <?php con_get_sharebox(); ?> that gets the contents of a file sharebox.php.

    Now the sharebox.php file is the file I’d like to edit but I don’t know how to do this using hooks.

    I tried simply adding a different sharebox.php to my child theme but because its not part of the standard theme files I don’t think it gets loaded.

    Any ideas on what I can do?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • If it is just the one function in the parent theme, then you could add this function to the child themes functions.php in a after_setup_theme hook

    You can create a new function (different name) and copy the code across, then in the child themes single.php call your new function.

    So in the child themes function.php

    add_action( 'after_setup_theme', 'my_post_theme_setup' );
    
    if ( !function_exists( 'my_post_theme_setup' ) ):
    function my_post_theme_setup() {
    
    	function my_get_sharebox() {
    		/* Add the modified code here */
    
    	}
    }
    endif;

    In the child themes single.php (copy file to child theme)
    <?php my_get_sharebox(); ?>

    If you want to include your own sharebox.php in the child theme then the functions in the file would need to have different names, apart from calls to parent functions, or you will get cannot redeclare function con_get_sharebox previously declared in file, blah blah!

    To include a file, from the child theme!
    require_once( STYLESHEETPATH. '/sharebox.php');

    Parent Theme TEMPLATEPATH and child theme STYLESHEETPATH

    HTH

    David

    Thread Starter mtbmtb

    (@mtbmtb)

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Should I use a wordpress hook to replace a file?’ is closed to new replies.