- This topic has 5 replies, 2 voices, and was last updated 5 years ago by Leo.
-
AuthorPosts
-
August 14, 2019 at 8:00 am #984071Josh
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!
August 14, 2019 at 8:19 am #984095LeoStaffCustomer SupportHi there,
I just tested the same code in Code Snippets and it worked for me:
https://www.screencast.com/t/GdqkPFWSoGP definitely doesn’t interfere with this.
August 14, 2019 at 2:55 pm #984367JoshThanks 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
August 14, 2019 at 3:35 pm #984384LeoStaffCustomer SupportLooks like it’s the wrong quotation there:
add_post_type_support( ‘page’, ‘excerpt’ );
It should be:
add_post_type_support( 'page', 'excerpt' );
August 14, 2019 at 3:44 pm #984389JoshOk that did it! I copied and pasted that from someone’s page. Nice catch, thanks.
August 14, 2019 at 3:45 pm #984391LeoStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.