• Resolved mitua

    (@mitua)


    Hi,

    Am using a child theme created from the parent by usual procedure.

    I am using a plugin in which some admin pages are there for which I have created the page templates so that the functionality can be used in frontend.And there is a functions.php file along with the pages in the plugin.so it has to be kept in the child theme.

    Now, I also want to create the pages automatically and the respective templates being assigned to them and also for any other template which I create I want automatic creation of pages.So for this purpose I would be required to add a function in the functions.php of the theme.Now since I cannot make any changes in the parent theme I would need to copy the functions.php into my child theme and then add the required function.Now there would be two problems:

    1) There would be two fuctions.php.one of the plugin and one of the theme.How to keep these two files with the same names in the child theme?

    2) If I am copying the functions.php from the parent theme into the child theme this will give error for two identical functions previously there.

Viewing 13 replies - 1 through 13 (of 13 total)
  • I would need to copy the functions.php into my child theme and then add the required function.

    No. Do not copy the parent theme functions.php to the child theme. Create a new blank functions.php file and add to your child theme – it needs to have the php open and close tags and between them your custom functions:

    <?php
    //your custom functions
    ?>

    Ask the plugin dev more about using their functions in your child theme.

    Thread Starter mitua

    (@mitua)

    Thanks for your reply.But again this will create two files with the same name namely-functions.php.One of the plugin and one which I will create in the child theme as you told.How to avoid this and at the same time both the files should be there in the child theme. I cannot rename also any of the two as wordpress won’t recognize it.I also cannot combine the two files.What could be a proper solution?

    Thread Starter mitua

    (@mitua)

    Thanks for your reply.But again this will create two files with the same name namely-functions.php.One of the plugin and one which I will create in the child theme as you told.How to avoid this and at the same time both the files should be there in the child theme. I cannot rename also any of the two as wordpress won’t recognize it.I also cannot combine the two files.What could be a proper solution?

    Thread Starter mitua

    (@mitua)

    I could not see my reply here in this thread so I thought the reply was not posted due to some errors.So I posted the reply again.Both the replies have appeared.Am sorry for the two identical replies above.Please ignore one.I have to check ‘how to delete the posts’ etc. in the forum if it can be done.

    I’m a little confused by your setup. Why wouldn’t you be able to use the plugin with your child theme? What plugin are you using?

    You could paste the PHP functions of your plugin in the child theme functions file.. Or use a custom PHP file and require/call it in the plugin template..

    Thread Starter mitua

    (@mitua)

    I didn’t have any knowledge not even abc of PHP and am learning like this only.Thanks for your reply Samuel, It was a wonderful answer.I will try the steps suggested by you.

    Thread Starter mitua

    (@mitua)

    I followed samuel’s reply but not exactly what he said.As I didn’t find it right to touch the plugin’s functions.php so instead of creating a custom php file for the plugin functions.php, I created a custom php file for child theme’s functions.php and called it in the templates which require that function.The plugin functions.php will be as it is and will serve the purpose of plugin page templates.
    Can there be any problem either presnt or further in doing this way?

    Thread Starter mitua

    (@mitua)

    No.The above solution to create a custom file for theme’s functions.php file did not work.So I need to follow exactly what Samuel had suggested.ButI have a doubt here that if I change the plugins functions.php file name to a custom name and use it ,are there any chances of any problem in the functioning of the plugin anytime?
    And thanks a lot to Pioneer valley and Samuel you had been a great help.

    @mitua sorry i have been on mobile and my computer’s away so couldn’t be more helpful in this tiny device..
    I think you can copy the plugin’s functions.php file content and paste it in your child theme functions file.. It should work i think..
    Otherwise by creating custom php file, you need to look up the entire plugin templates and make calls to that custom file when needed, for example somewhere where functions need values and callbacks etc..
    And of course when the plugin updates all changes made in the plugin files will be lost, that’s why i go thinking it would be better putting everything in theme functions file..

    Thread Starter mitua

    (@mitua)

    Samuel thank you again for taking out time to reply again.I need to try this.I had applied your other solution of making custom file for plugin’s functions.php and it worked but only was my doubt for which you have mentioned the consequences.But updates on plugin wont affect this I think because am using a custom functions file of the plugin and also the custom pages.the only thing is I need to call them whenever required so that should not be a problem.

    And as far as the solution to copy the plugins functions in the child’s theme’s functions.php it is I think a bigger risk and problematic as a slight error/problem in the functions file will affect the functionality of the plugin.And it was advisable to keep the functions.php of plugin untouched.So i think it would be better to create a custom function file for plugin and calling it.

    What do you suggest now?I will wait for your answer.

    You’re welcome. I am not really familiar with PHP but I agree with what you mentioned above.
    I assume your plugin has a functions.php file, and you have already created a custom-functions.php file located in your child theme containing the plugin functions so, you can edit the plugin functions file in the plugin directory to require your custom one.. Something like :
    require( '../themes/twentyfifteen-child/custom-functions.php' ); inserted at the top.. Make sure you got the absolute path.
    Doing so I don’t think you need to look up everything as the plugin relies on their functions.php file already, and you can only edit it after every updates to insert the custom file requiring line..

    Let us know how it goes..

    Thread Starter mitua

    (@mitua)

    OK.I am marking it as resolved.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to keep two functions.php in the same theme’ is closed to new replies.