This topic has 10 replies, 3 voices, and was last updated 9 years by Andrei.

  • Author
  • #74038
     adamdale1
    Participant

    I’ve been developing Sweetdate for over a year, mainly testing and implementing facilities, testing plugin and writing new software! Now my problem is I know changes I make to the main file and get working, will be over written by upgrades and updates! I can’t get a handle on the Child theme, I understand that main files, load first, then Changes stored in the Child field are given preference!

    I’ve stopped updating all plugins and especially WordPress, knowing that all changes I’ve made will be over written with the default items, thus loosing my changes in some cases forever because the change came in a moment of inspiration and at the tome I did bot save a copy!

    Now after reading all I can on the Child theme and experiment, there’s something I’ve missed, experimenting with the Child have had numerous errors occur taking the site down or not giving preference to the changes!
    I’ve found that for example you can’t just copy the main function theme to the Child and add changes there, because you get an error that you can’t double up!

    I need a simple example of say the main functions.php and and how it would look in the Child theme with addition code someone has added to overwrite the main theme.

    #74046
     dunnyuk
    Participant

    the original fuctions.php is in – your downloaded files, main files, wordpress, sweetdate-child.

    heres mine………… (im not staff here – just a user like yourself)

    COPY CODE
    <?php
    
    /**
    
     * @package WordPress
    
     * @subpackage Sweetdate
    
     * @author SeventhQueen <themesupport@seventhqueen.com>
    
     * @since Sweetdate 1.0
    
     */
    
    /**
    
     * Sweetdate Child Theme Functions
    
     * Add extra code or replace existing functions
    
    */ 
    
    /**
    
    * Redirect buddypress and bbpress pages to registration page
    
    */
    
    function kleo_page_template_redirect()
    
    {
    
        //if not logged in and on a bp page except registration or activation
    
        if( ! is_user_logged_in() &&
    
            ( ( ! bp_is_blog_page() && ! bp_is_activation_page() && ! bp_is_register_page() ) || is_bbpress() )
    
        )
    
        {
    
            wp_redirect( home_url( '/register/' ) );
    
            exit();
    
        }
    
    }
    
    add_action( 'template_redirect', 'kleo_page_template_redirect' );
    
    add_action('after_setup_theme','kleo_my_hearts_actions');
    
    function kleo_my_hearts_actions() 
    
    {
    
       /* disable matching on member profile */
    
        remove_action('kleo_bp_before_profile_name', 'kleo_bp_compatibility_match');      
    
        /* Replace the heart over images */
    
        add_filter('kleo_img_rounded_icon', 'my_custom_icon');
    
        /* Replace the heart from register modal */
    
        add_filter('kleo_register_button_icon', 'my_custom_icon_register');
    
        /* Replace the heart from About us widget */
    
        add_filter('kleo_widget_aboutus_icon', 'my_custom_icon_about_widget');
    
    }
    
    /* Replace the heart with a camera icon function */
    
    function my_custom_icon () {
    
        return 'camera';
    
    }
    
    /* Replace the heart from register modal with a user icon function */
    
    function my_custom_icon_register () {
    
        return 'user';
    
    }
    
    /* Replace the heart from about us widget with a user icon function */
    
    function my_custom_icon_about_widget () {
    
        return 'user';
    
    }
    
    ?>
    Attachments:
    You must be logged in to view attached files.
    #74063
     adamdale1
    Participant

    Thankyou, for the reply and a copy of your child functions.php I’ve examined the code, I see you added code, my simple question is, is the Sweetdate functions.php still the original as downloaded or modified? I’ll re-examine it, tomorrow when I have a clear head!

    #74177
     dunnyuk
    Participant

    the functions.php file is just a txt file – edit it with notepad ++
    use your original vs thae one above to see changes.

    #74887
     Andrei
    Moderator

    Hi @adamdale1, we provide a demo child theme for you to start from, but in order to understand how it works I recommend you to do some more research about this topic or watch some video tutorials. You can find lots of resources regarding wordpress child themes over the internet.

    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #75905
     adamdale1
    Participant

    I started with Sweetdate over a year and a half ago! Due to a browser update, I can’t run it on my localhost not your problem! So it’s working off a Host, basically on line! I know that changes to the main theme should be done in the child! For some reason, how to do this is eluding me! I’ve read nearly every article on the subject and links to information on the child ,have wasted my time! I need to understand the operation of the child theme, then I can implement my changes without loosing them, so far every effort in reference to the child has caused an error, taking the site down, taking me in circles!

    So I’ll keep the question simple, I need to add a function to index.php of the Sweetdate theme called v_main.php, I added it numerous times, I now loathe any updates whether WordPress or plugins! The theme and function is working, but then it stops, when I check the original file is there again minus my additions! So far everything I’ve tried has taken my site down!

    So taking it that I want to add “require v_main.php” to index.php in the theme, what and how? Do I do to make an index.php file in the child theme to take precedence over the theme’s index.php. No links please, just a simple example and description please! This has frustrated me since I started and now is causing me the most problems, If you can’t help with the response, please don’t reply! I don’t need a maze opened again, leading me back to here after fruitless hours of research!

    #76125
     dunnyuk
    Participant

    the fuctions.php in the main sweetdate theme folder is different from the child theme fuctions.php only in its content, or lack of…

    the child theme version is a blank canvas so to speak because of this ->

    ——————————————————————————————————————–
    A child theme consists of at least one directory (the child theme directory) and two files (style.css and functions.php), which you will need to create:

    Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)
    https://codex.wordpress.org/Child_Themes
    ——————————————————————————————————————-

    so the original is a “full” file so to speak and the child one just has a few needed php lines within which to add things. that would be why if you copied the whole file over to the child – wordpress spat its dummy….

    child theme function.php supplied with theme.

    COPY CODE
    <?php
    /**
     * @package WordPress
     * @subpackage Sweetdate
     * @author SeventhQueen <themesupport@seventhqueen.com>
     * @since Sweetdate 1.0
     */
    
    /**
     * Sweetdate Child Theme Functions
     * Add extra code or replace existing functions
    */ 
    
    ?>

    then lets say you need to edit a different file all you do is copy the file from the main theme and place it in the child theme folder – making sure you copy the folder structure – then make your edits to it and it will override the original – leaving it safe to update at a later date.

    7thqueen have been nice enough to make the child theme for us – im using it and everythings going fine for me so far.(its my first time using a child theme)

    so my take on it is – the functions.php is for making sitewide changes, and for more specific changes – find the file you need to change then copy it to the child and the folder structure its in then edit away…

    that 1 page linked up there tells you all you need to know. give it a read.(it will take you 10 mins max)

    so your index.php – copy it – place it in the child theme folder in the same place as the original and that should be it.
    hope this helps.

    #76311
     Andrei
    Moderator

    @dunnyuk thank you very much for your time in providing a few words on this subject.


    @adamdale1
    , please understand that what you’re trying to learn has basics in programming, so you should need to understand html/php and also start knowing wordpress template system and a few other wordpress related things.

    If you want to understand how to do them by yourself then you’ll have to spend some serious time learning, if you just want some of your modifications fixed quickly, then you can hire someone to help you do them.

    Related to our support, we are already providing a lot of awesomeness around here but unfortunately we don’t have time and it is not in our priorities to learn our customers how to code.

    Please let me know if I can help you with anything else.
    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #76343
     adamdale1
    Participant

    Dear Andrei,
    Thank you, for your response and this is the last attempt at an answer to my question, just wondering if questions on the child theme are read or if because child theme is mentioned it an automated response to point to links and not even read the question ? I’m one of the original programmers, I was writing software before there were machines, but processors, working in machine code! And have been involved in all aspect of programming since then, but for a period of time, during which a number of new languages came into existence, since then I believe I’ve caught up! Please read this all, before responding! My site is still in testing mode, it’s not advertised and not working at this time on the Internet, but is on a Host! The front door to the site has had 12,500 visitors to date, on checking they have been bots and hackers, some have bypassed some security measures in place and accessed the test sites! When identified, measures were put into place to disallow that access point.

    I have spent a year and a half learning creating software in php, for the Sweetdate theme! I’ve created functions that originally had a page of code and reduced them to a few lines, and they work like the original, but the now hundreds of thousand of lines of information I’ve read in documentation, forums etc. on child themes led me to try experimenting, adding files etc. to the child, that have not had any effect at all and any updates can overwrite my work! Before I ask I research all avenues, then ask! I got amused when I saw the same questions in this forum, asked over and over again, I did help out pointing users to the solution, but then found that, even when the solution was noted on the front page for all to read, they still asked it without any search! So stopped

    I understand that functions.php in the theme and child complement each other! It also states that other files like index.php placed in the child theme overwrite the same in the theme itself, giving it preference!

    I’ve checked and analysed the code I’ve put in the child, as far as I can tell it’s correct by the information I have and read at this time, yes, everything I have done is backed up and documented by me! The functions.php is not a problem now, but any changes I’ve made in the theme itself, will be lost if I update, the information I’ve read all makes sense, but there is a snippet I’ve either missed or has not been mentioned! So every attempt at trying to implement code into the child has had a catastrophic, minor failure or has not worked! So I’ll keep it simple the following is my index.php, the standard WordPress version and any changes or additions made to it will revert back to this original on an update!

    <?php
    /**
    * Front to the WordPress application. This file doesn’t do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define(‘WP_USE_THEMES’, true);

    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ );

    To it I want to add … require(‘./c_main.php’);
    just below <?php … I have now lost count the number of times I’ve added it and sometime later found that’s it’s reverted to the original and the number of times I’ve asked for an example of code to put in the child theme to be told, read this or that or it’s as simple as 1, 2, 3, not giving me any code at all ! I’m almost at the stage of abandoning my project and starting again in a totally different language, the only reason I’ve continued is the sizeable investment in money and time, I’ve already put into this project!

    If you ask why not put the function somewhere else where it won’t be updated, well the main reason index.php is the entry point to the site, anywhere else the user is already on the site and can possibly if smart enough bypass what this function does!

    The following is the modified index.php that works till an up date!

    <?php
    require(‘./c_main.php’);
    /**
    * Front to the WordPress application. This file doesn’t do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define(‘WP_USE_THEMES’, true);

    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ );

    Just the addition of one line of code above which is in bold to highlight it, all I’ve read, says put the above into the child theme, it doesn’t say where? And doesn’t say much, whether it requires some sort of pointer or whatever to be implemented!
    So is this code correct to be put in the child theme? If not what would the code be? Does it need to go into a specific directory or not? Do I require additional code somewhere else in the child? Or is this beyond the scope of this forum and I have to go to the WordPress experts? I understand a simple example easier than explanations!

    #76344
     adamdale1
    Participant

    Sorry to you, dunnyuk, for not acknowledging your response, so thank you, it re-asserted the information I already had! I’ve found in other areas where I’ve had a problem, after pains taking research that one tiny snippet of information is missing, and now days without the key word or phrase, you get caught in an never ending circle, until by accident you find it and then Abracadabra it all falls into place and you have a solution!

    #76345
     Andrei
    Moderator

    You shouldn’t even touch any files outside plugins or themes folders, in your example you’re injecting a file in the main index file from the root folder.

    So let’s take it step by step.
    A theme is build by :
    – a style.css file, which has some comments in the header that defines a few things
    – the template files ( http://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg )
    – template parts ( https://kovshenin.com/2013/get_template_part/ )
    – the functions.php file which is the primary point where you can start extending wordpress.
    – all kind of other files that are outside the main template hierarchy files are extensions of features or all kind of developments and logics which are included or required from the functions.php file

    You can understand much of this better by reading this page: https://codex.wordpress.org/Theme_Development

    So what happens in the child theme ? Well, a child theme is defined in it’s style.css file headers, where is related/linked to it’s parent. You already learned that a child theme can be build of only the style.css and the functions.php file. That’s because the system will automatically know to load anything from the parent theme.

    On the child theme you can come and copy any files that make part of the main templating system or that has built a manually check for allowing overriding in the child theme, because not all files copy from the main theme to the child theme will work by default. Almost all the custom included files can’t be overridden in this manner.

    In your case I think you should move your require into the /sweetdate-child/functions.php file. Not it might depends of what it contains. I also recommend you to learn how the hooks and filters wordpress system works, it will help you a lot: http://code.tutsplus.com/articles/the-beginners-guide-to-wordpress-actions-and-filters–wp-27373

    This reply doesn’t cover all, of course, but hope it helps you.
    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 11 posts - 1 through 11 (of 11 total)

The forum ‘Sweetdate – WordPress’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?