theme-shortcodes.php doesn't work in betheme-child

Hi,

I have two questions about betheme-child:

1.)
I wanted to change a part in theme-shortcodes.php. I use the child theme, so I added a folder named "functions" and copied the original theme-shortcodes.php into that folder. Then I edited the file but the changes didn't change anything. The edited theme-shortcodes.php must stay in the parent theme's "functions" folder to take effect.

2)
I copied the original functions.php. to betheme-child and added some woocommerce functions. The result was a blank page. After deleting the original functions.php in the parent theme it works.

....but then a child theme is useless.

Where is the (or my) mistake?

Comments

  • Hi,

    at 1st please update theme to latest version (6.3) because we did some fixes for child theme :) And 2nd, please take a look at http://codex.wordpress.org/Child_Themes because now everything should work exactly the same way.

    Hope this will help you a lot.
  • Thanks, the problem with the functions.php is solved with the 6.3 update. But the /functions/theme-shortcodes.php is still totally ignored.

    I studied http://codex.wordpress.org/Child_Themes:

    "If you want to change more than just the stylesheet, your child theme
    can override any file in the parent theme: simply include a file of the
    same name in the child theme directory, and it will override the
    equivalent file in the parent theme directory when your site loads."

    But it does not. I couldn't find the mistake. The modified /functions/theme-shortcodes.php only works in the parent theme. :-/
  • Hi,

    please try this:

    Copy the betheme/functions/theme-shortcodes.php to betheme-child/functions. Then edit a shortcut a bit and see what happens. I bet the change will be ignored.

    The funny thing is, that I edited lots of the files in the woocommerce folder and it works like expected.

  • When you use child theme, all changes must be done in functions.php file. If you want to use the same file as we do (theme-shortcodes.php) you must use require_once() function in functions.php to include this file.

    functions.php file should look like below:
    1. <?php

      /* ---------------------------------------------------------------------------
       * White Label
       * --------------------------------------------------------------------------- */
      define( 'WHITE_LABEL', false );


      /* ---------------------------------------------------------------------------
       * Enqueue Style
       * --------------------------------------------------------------------------- */
      add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style', 101 );
      function enqueue_parent_theme_style() {
          wp_enqueue_style( 'mfn-parent-style', get_template_directory_uri() .'/style.css' );
          wp_enqueue_style( 'mfn-child-style', get_stylesheet_directory_uri() .'/style.css' );
      }

      /* ---------------------------------------------------------------------------
       * Shortcodes
       * --------------------------------------------------------------------------- */
          function sc_alert( $attr, $content = null )
          {
              extract(shortcode_atts(array(
                  'style'        => 'warning',
              ), $attr));

              switch( $style ){
                  case 'error':
                      $icon = 'icon-alert';
                      break;
                  case 'info':
                      $icon = 'icon-help';
                      break;
                  case 'success':
                      $icon = 'icon-check';
                      break;
                  default:
                      $icon = 'icon-lamp';
                      break;
              }
                 
      //         $output  = '<div class="alert alert_'. $style .'">';
      //             $output  .= '<div class="alert_icon">';
      //                 $output .= '<i class="'. $icon .'"></i>';
      //             $output .= '</div>';
      //             $output .= '<div class="alert_wrapper">';
      //                 $output .= do_shortcode( $content );
      //             $output .= '</div>';
      //             $output .= '<a href="#" class="close"><i class="icon-cancel"></i></a>';
      //         $output .= '</div>'."\n";

              $output  = 'MY ALERT CODE';

              return $output;
          }

      ?>
  • Thank you, now it works! =D>
    Have a great day!
  • We're very happy to hear that this works now :) You're welcome!
  • Hi, I have the same problem, but your solution seems not working.
    If I insert a require_once('functions/theme-shortcodes.php') or even require_once( LIBS_DIR .'/theme-shortcodes.php' ) in my betheme-child/functions.php, my website stop working (I think it's due to duplicated functions declaration in PHP).

    Where I'm wrong?

    Can you help me?

    Thanks in advance
  • @bmarini Please check https://codex.wordpress.org/Child_Themes because for sure you did something wrong while creating child theme.
  • Hi, my child seems to be ok.
    When I try to include the theme-shortcodes.php in my functions.php, the PHP error shown is:

    Fatal error: Call to undefined function mfn_opts_get() in [mypath]/wp-content/themes/betheme-child/functions/theme-shortcodes.php on line 4417
  • @bmarini You can only include functions from this file. You can't include whole file.
Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.