Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1139671

    Hi

    I have tried to create a child theme for Enfold Theme. Everything seems to be ok. However, after I insert code into functions.php file in child theme directory. It immediate broke my site. Not sure whether I insert the code into wrong line or not. Please kindly suggest me. Below is my child theme’s functios.php. The italic code below are the code that I inserted

    <?php
    function themevilles_enqueue_styles() {

    $parent_style = ‘parent-style’;

    wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
    wp_enqueue_style( ‘child-style’,
    get_stylesheet_directory_uri() . ‘/style.css’,
    array( $parent_style ),
    wp_get_theme()->get(‘Version’)
    );
    }
    add_action( ‘wp_enqueue_scripts’, ‘themevilles_enqueue_styles’ );

    //set builder mode to debug
    add_action(‘avia_builder_mode’, “builder_set_debug”);
    function builder_set_debug()
    {
    return “debug”;
    }

    /* Automatically set the image Title, Alt-Text, Caption & Description upon upload
    ———————————————————————–*/
    add_action( ‘add_attachment’, ‘my_set_image_meta_upon_image_upload’ );

    function my_set_image_meta_upon_image_upload( $post_ID ) {
    // Check if uploaded file is an image, else do nothing
    if ( wp_attachment_is_image( $post_ID ) ) {
    $my_image_title = get_post( $post_ID )->post_title;
    // Sanitize the title: remove hyphens, underscores & extra
    // spaces:
    $my_image_title = preg_replace( ‘%\s*[-_\s]+\s*%’, ‘ ‘,
    $my_image_title );
    // Sanitize the title: capitalize first letter of every word
    // (other letters lower case):
    $my_image_title = ucwords( strtolower( $my_image_title ) );
    // Create an array with the image meta (Title, Caption,
    // Description) to be updated
    // Note: comment out the Excerpt/Caption or Content/Description
    // lines if not needed
    $my_image_meta = array(
    // Specify the image (ID) to be updated
    ‘ID’ => $post_ID,
    // Set image Title to sanitized title
    ‘post_title’ => $my_image_title,
    // Set image Caption (Excerpt) to sanitized title
    ‘post_excerpt’ => $my_image_title,
    // Set image Description (Content) to sanitized title
    ‘post_content’ => $my_image_title,
    );

    // Set the image Alt-Text
    update_post_meta( $post_ID, ‘_wp_attachment_image_alt’,
    $my_image_title );
    // Set the image meta (e.g. Title, Excerpt, Content)
    wp_update_post( $my_image_meta );
    }
    }

    ?>

    • This topic was modified 4 years, 9 months ago by pingbara.
    #1139810

    can you please use the code tag here on board when presenting code.
    to prove if there are errors it is important to see if all signs are right ( Brackets, Quotes and Doublequotes etc)

    #1139815

    First of all – why dont you use the prestyled child-theme from Enfold? https://kriesi.at/documentation/enfold/child-theme/

    you don’t need to include the parent style via functions.php if the style.css of the child-theme is well set up.
    This is the content of the style.css of the child-theme:

    /*
    Theme Name: Enfold Child
    Description: A <a href='http://codex.wordpress.org/Child_Themes'>Child Theme</a> for the Enfold WordPress Theme. If you plan to do a lot of file modifications we recommend to use this Theme instead of the original Theme. Updating wil be much easier then.
    Version: 1.0
    Author: Kriesi
    Author URI: http://kriesi.at
    Template: enfold
    */
    
    /*Add your own styles here:*/

    The template ( is the name of the parent folder ) that is important

    The download includes a functions.php file ( empty at the beginning )
    on that you can see that there is no closing tag ( ?> )

    #1139827

    Hi Guenni007

    Thank you very much for your help, everything is ok now. After I downloaded the version in your link and insert my custom php file.
    The problem because in the previous version of mine, I inserted php code in wrong line. it must be between /* … */

    Thanks alot

    Best Regards,

    Methee S.

    #1140547

    Hi Methee,

    Great, I’m glad that you got things working and I’m glad that @guenni007 could help you out. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.