[Resolved] 'Add Excerpt to Page' Code Won't Run in Code Snippets Plugin

Home Forums Support [Resolved] 'Add Excerpt to Page' Code Won't Run in Code Snippets Plugin

Home Forums Support 'Add Excerpt to Page' Code Won't Run in Code Snippets Plugin

  • This topic has 5 replies, 2 voices, and was last updated 5 years ago by Leo.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #984071
    Josh

    So I have a need to add an Except field to Single Pages.

    I’m trying to run this code in functions.php:

    /* Add excerpt field to single page */
    add_post_type_support( 'page', 'excerpt' );

    When I run it in the Code Snippets plugin, it doesn’t work

    When I add the same code manually to functions.php, it works fine. The Excerpt field shows up on the page Edit screen.

    Code Snippets is running other snippets just fine. I’d rather not have to make a child theme only to run one tiny bit of code.

    I’ve cleard my browser cache and no other caching programs are running on site at the moment. Thanks!

    #984095
    Leo
    Staff
    Customer Support

    Hi there,

    I just tested the same code in Code Snippets and it worked for me:
    https://www.screencast.com/t/GdqkPFWSo

    GP definitely doesn’t interfere with this.

    #984367
    Josh

    Thanks Leo – anything you can suggest to try and troubleshoot this? I tried using the Code Snippets method on a couple of my other sites. But all of my builds have a standard setup (plugins, code) and it did not work there either.

    Same thing: other snippets work fine. Just not this one.

    In the meantime I downloaded the child theme zip and tried that method:

    <?php
    
    /**
    
     * GeneratePress child theme functions and definitions.
    
     *
    
     * Add your custom PHP in this file. 
    
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
    
     */
    
    function generatepress_child_enqueue_scripts() {
    
    	if ( is_rtl() ) {
    
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    
    	}
    
    }
    
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    
    /* Adding excerpt for page */
    add_post_type_support( ‘page’, ‘excerpt’ );
    
    

    The site returns this error:

    Warning: Use of undefined constant ‘page’ - assumed '‘page’' (this will throw an Error in a future version of PHP) in /[PATH TO CHILD THEME DIRECTORY]/functions.php on line 31

    Thanks

    #984384
    Leo
    Staff
    Customer Support

    Looks like it’s the wrong quotation there:
    add_post_type_support( ‘page’, ‘excerpt’ );

    It should be:
    add_post_type_support( 'page', 'excerpt' );

    #984389
    Josh

    Ok that did it! I copied and pasted that from someone’s page. Nice catch, thanks.

    #984391
    Leo
    Staff
    Customer Support

    No problem 🙂

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