Child theme shortcodes.php - by Gerhard - on WordPress WooCommerce support

This topic has 9 replies, 4 voices, and was last updated 9 years ago ago by Jack Richardson

  • Avatar: Team Borijn
    Gerhard
    Participant
    December 18, 2015 at 15:45

    Hello,

    Child theme: when I want to make changes to the framework shortcodes.php do I have to copy the framework folder and the shortcodes.php to the child theme and edit that one? Do I have to make changes to the functions.php in childtheme to make that work? Or is it better work with custom css? My goal is to translate fieldnames in the contactform.php

    Best regards,

    Gerhard

    8 Answers
    Avatar: Robert Hall
    Robert Hall
    Support staff
    December 18, 2015 at 16:09

    Hello,

    Yes, you should save folder structure, for example
    \wp-content\themes\woopress-child\framework and here use shortcode.php file with your changes.

    Regards,
    Robert Hall.

    Avatar: Team Borijn
    Gerhard
    Participant
    December 18, 2015 at 17:09

    Thanks!
    No changes in functions.php to get this to work?

    Best regards,

    Gerhard

    Avatar: Eva
    Eva Kemp
    Support staff
    December 20, 2015 at 11:07

    Hello,

    You need copy the function code from shortcodes.php to functions.php in childtheme. After this your changes should work.

    Regards,
    Eva Kemp.

    Avatar: Robert Hall
    Robert Hall
    Support staff
    December 21, 2015 at 13:54

    Hello @Team Borijn,

    Please read this article (5. Pluggable Functions)
    https://support.woothemes.com/hc/en-us/articles/203105897-How-to-set-up-and-use-a-child-theme

    In our theme the function of the social icons isn’t pluggable. We’ll fix it in the next theme update.
    Also I’ve added this function for you. Now you can copy the function code as Eva Kemp wrote above and it should work fine.

    Regards,
    Robert Hall.

    Avatar: Team Borijn
    Gerhard
    Participant
    December 23, 2015 at 22:06

    Hello,

    Late reaction I am sorry.
    Can you tell me which function from shortcodes to copy to the functions.php in child? And to which location in this file?

    What do you mean by I added this function for you with respect to social icons? Where did you add this because the child theme was not active at that moment and it also is not changed by you?

    Best regards,
    Team Borijn

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    December 24, 2015 at 09:11

    Hello,

    Please clarify what exactly you want to edit and to what content, and we’ll help you with it.

    Best regards,
    Jack Richardson.

    Avatar: Team Borijn
    Gerhard
    Participant
    December 24, 2015 at 10:14

    Hello,

    @eva: the function code from shortcodes.php to functions.php in childtheme; please specify the


    @robert
    : Also I’ve added this function for you: please specify this

    I disabled child for now as it doesn’t work, so what functions do I need to copy to which location in functions.php of the child theme with respect to changing widgets.php (to get the year with the latest widgets), shortcodes.php (for changing the contact form), and mentioned by you getting social icons to work.

    best regards,

    Team Borijn

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    December 24, 2015 at 12:39

    Hello,

    To edit contact form you need copy this function to file functions.php in the child theme and make changes you need:

    if(!function_exists('et_contact_form')) {
      function et_contact_form($atts) {
        extract( shortcode_atts( array(
          'class' => ''
        ), $atts ) );
        
        $captcha_instance = new ReallySimpleCaptcha();
        $captcha_instance->bg = array( 244, 80, 80 );
        $word = $captcha_instance->generate_random_word();
        $prefix = mt_rand();
        $img_name = $captcha_instance->generate_image( $prefix, $word );
        $captcha_img = ETHEME_CODE_URL.'/inc/really-simple-captcha/tmp/'.$img_name;
    
        ob_start();
        ?>
            <div id="contactsMsgs"></div>
            <form action="<?php the_permalink(); ?>" method="get" id="contact-form" class="contact-form <?php echo $class; ?>">
                
                <div class="form-group">
                  <p class="form-name">
                    <label for="name" class="control-label"><?php _e('Name and Surname', ETHEME_DOMAIN) ?> <span class="required">*</span></label>
                    <input type="text" name="contact-name" class="required-field form-control" id="contact-name">
                  </p>
                </div>
    
                <div class="form-group">
                    <p class="form-name">
                      <label for="contact-email" class="control-label"><?php _e('Email', ETHEME_DOMAIN) ?> <span class="required">*</span></label>
                      <input type="text" name="contact-email" class="required-field form-control" id="contact-email">
                    </p>
                </div>
                
                <div class="form-group">
                  <p class="form-name">
                    <label for="contact-website" class="control-label"><?php _e('Website', ETHEME_DOMAIN) ?></label>
                    <input type="text" name="contact-website" class="form-control" id="contact-website">
                  </p>
                </div>
                
    
                <div class="form-group">
                  <p class="form-textarea">
                    <label for="contact_msg" class="control-label"><?php _e('Message', ETHEME_DOMAIN); ?> <span class="required">*</span></label>
                    <textarea name="contact-msg" id="contact-msg" class="required-field form-control" cols="30" rows="7"></textarea>
                  </p>
                </div>
                
                <div class="captcha-block">
                  <img src="<?php echo $captcha_img; ?>">
                  <input type="text" name="captcha-word" class="captcha-input">
                  <input type="hidden" name="captcha-prefix" value="<?php echo $prefix; ?>">
                </div>
                
                <p class="pull-right">
                  <input type="hidden" name="contact-submit" id="contact-submit" value="true" >
                  <span class="spinner"><?php _e('Sending...', ETHEME_DOMAIN) ?></span>
                  <button class="btn btn-black big" id="submit" type="submit"><?php _e('Send message', ETHEME_DOMAIN) ?></button>
                </p>
    
                <div class="clearfix"></div>
            </form>
        <?php
        $output = ob_get_contents();
        ob_end_clean();
        
        return $output;
      }
    }

    and add this code to child functions.php:

    function Etheme_Recent_Posts_Widget() {
            $widget_ops = array('classname' => 'etheme_widget_recent_entries', 'description' => __( "The most recent posts on your blog (Etheme Edit)", ETHEME_DOMAIN) );
            parent::__construct('etheme-recent-posts', '8theme - '.__('Recent Posts', ETHEME_DOMAIN), $widget_ops);
            $this->alt_option_name = 'etheme_widget_recent_entries';
    
            add_action( 'save_post', array(&$this, 'flush_widget_cache') );
            add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
            add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
        }
    
        function widget($args, $instance) {
            $cache = wp_cache_get('etheme_widget_recent_entries', 'widget');
    
            if ( !is_array($cache) )
                    $cache = array();
    
            if ( isset($args['widget_id']) && isset($cache[$args['widget_id']]) ) {
                    echo $cache[$args['widget_id']];
                    return;
            }
    
            ob_start();
            extract($args);
    
            $box_id = rand(1000,10000);
    
            $title = apply_filters('widget_title', empty($instance['title']) ? false : $instance['title']);
            if ( !$number = (int) $instance['number'] )
                    $number = 10;
            else if ( $number < 1 )
                    $number = 1;
            else if ( $number > 15 )
                    $number = 15;
    
            $slider = (!empty($instance['slider'])) ? (int) $instance['slider'] : false;
    
            $r = new WP_Query(array('posts_per_page' => $number, 'post_type' => 'post', 'post_status' => 'publish', 'ignore_sticky_posts' => 1));
            if ($r->have_posts()) : ?>
            <?php echo $before_widget; ?>
            <?php if ( $title ) echo $before_title . $title . $after_title; ?>
                <?php if($slider): ?>
                    <div class="owl-carousel blogCarousel slider-<?php echo $box_id; ?>">
                <?php endif; ?>
    			<ul class="blog-post-list slide-item">
                    <?php $i=0;  while ($r->have_posts()) : $r->the_post(); $i++; ?>
    	                <?php
    	                    if ( get_the_title() ) $title = get_the_title(); else $title = get_the_ID();
    	                    $title = trunc($title, 10);
    	                ?>
    					<li>
    						<div class="media">
    							<a class="pull-left" href="#">
    								<time class="date-event"><span class="number"><?php the_time('d'); ?></span> <?php the_time('M'); ?></time>
    							</a>
    							<div class="media-body">
    								<h4 class="media-heading"><a href="<?php the_permalink() ?>"><?php echo $title; ?></a></h4>
    								<?php _e('by', ETHEME_DOMAIN) ?> <strong><?php the_author(); ?></strong> <?php the_time('M'); ?> <?php the_time('d'); ?> <?php the_time('y'); ?>
    							</div>
    						</div>
                        </li>
                    <?php if($i%2 == 0 && $i != $r->post_count): ?>
                            </ul>
                            <ul class="blog-post-list slide-item">
                    <?php endif; ?>
                    <?php endwhile; ?>
                </ul>
                <?php if($slider): ?>
                    </div>
                    <script type="text/javascript">
                        jQuery(document).ready(function($) {
                            jQuery(".slider-<?php echo $box_id; ?>").owlCarousel({
                                items:1,
                                navigation: true,
                                lazyLoad: true,
                                rewindNav: false,
                                addClassActive: true,
                                itemsCustom: [1600, 1]
                            });
                        });
                    </script>
                <?php endif; ?>
            <?php echo $after_widget; ?>
    <?php
                    wp_reset_query();  // Restore global post data stomped by the_post().
            endif;
            
            if(isset($args['widget_id'])) {
    	        $cache[$args['widget_id']] = ob_get_flush();
    	        wp_cache_add('etheme_widget_recent_entries', $cache, 'widget');
            }
        }
    
        function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title'] = strip_tags($new_instance['title']);
            $instance['number'] = (int) $new_instance['number'];
            $instance['slider'] = (int) $new_instance['slider'];
            $this->flush_widget_cache();
    
            $alloptions = wp_cache_get( 'alloptions', 'options' );
            if ( isset($alloptions['etheme_widget_recent_entries']) )
                    delete_option('etheme_widget_recent_entries');
    
            return $instance;
        }
    
        function flush_widget_cache() {
            wp_cache_delete('etheme_widget_recent_entries', 'widget');
        }
    
        function form( $instance ) {
            $title = esc_attr($instance['title']);
            if ( !$number = (int) $instance['number'] )
                    $number = 5;
    
            $slider = (int) $instance['slider'];
    ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', ETHEME_DOMAIN); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
    
            <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:', ETHEME_DOMAIN); ?></label>
            <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /><br />
            <small><?php _e('(at most 15)', ETHEME_DOMAIN); ?></small></p>
    
            <?php etheme_widget_input_checkbox(__('Enable slider', ETHEME_DOMAIN), $this->get_field_id('slider'), $this->get_field_name('slider'),checked($slider, true, false), 1); ?>
    
    <?php
        }

    You need add under all content in child functions.php.

    If you have any difficulties provide us with correct WP Dashboard credentials.

    Best regards,
    Jack Richardson.

  • Viewing 9 results - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.