• Hi,
    I’ve added a snippet of code to my functions.php file in my Twenty-Twelve Child Theme, but it has come up as a parse error. I know I’m doing something wrong, can anyone advise?
    I’ve added it like this and saved…

    <?php
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    }
    ?>
    
    <?php if ( is_search() || is_archive() || is_author() || is_tag() || is_home() ) : // Only display Excerpts ?>

    Many thanks in advance,

    Stuart

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    You are missing the end of If tag.
    Please use the code below and see if it works for you.

    <?php
    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    function theme_enqueue_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );

    }
    ?>

    <?php if ( is_search() || is_archive() || is_author() || is_tag() || is_home() ) : // Only display Excerpts
    endif;
    ?>

    Thanks

    Thread Starter sbgolledge

    (@sbgolledge)

    Many thanks for your quick response!

    I’ve made the ammendment and now get this on the top of my website?

    Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at /home1/karmafree/public_html/wp-content/themes/twentytwelve-child/functions.php:9) in /home1/karmafree/public_html/wp-content/plugins/custom-contact-forms/classes/class-ccf-form-handler.php on line 587

    I’ve now removed the code again. Any thoughts? I’d ideally like the site to display like this https://karma-free-life.com/?s=garlic (I’ll of course add featured tiles) with perhaps ‘read more’ links, once I get the basics sorted.

    Many thanks,

    Stuart

    Hi,

    Please change the above code which was previously posted by us as follows:

    <?php
        add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    
        function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
        }
    
      if ( is_search() || is_archive() || is_author() || is_tag() || is_home() ) :
            // Only display Excerpts
      endif;
        ?>

    Please let us know if it solves your problem.

    Thanks

    Thread Starter sbgolledge

    (@sbgolledge)

    Hi, Clarion Technologies,

    Many thanks, again, but, no, this had no effect in adding excerpts to my site.

    I’m totally baffled!

    Stuart

    @sbgolledge: If I’m understanding what your aim is here, then you need something more than just this comment:

    // Only display Excerpts

    For example, you’d need <?php the_excerpt(); ?> there in order to actually display an excerpt.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding Code to functions.php in Child Theme’ is closed to new replies.