Archived topic
'Add Excerpt to Page' Code Won't Run in Code Snippets Plugin
5 replies · Started by Josh on August 14, 2019
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!
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.
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
Looks like it's the wrong quotation there:
add_post_type_support( ‘page’, ‘excerpt’ );
It should be:
add_post_type_support( 'page', 'excerpt' );
Ok that did it! I copied and pasted that from someone's page. Nice catch, thanks.
No problem :)