- This topic has 5 replies, 2 voices, and was last updated 5 years, 9 months ago by
David.
-
AuthorPosts
-
August 16, 2020 at 6:15 pm #1405512
Sophie
Hi there! I’m new to this theme and using it alongside Elementor Pro.
I want to add custom post types for portfolios, and have read that while a plugin may be easier this isn’t always ideal in case there are issues with the plugin.
Therefore I’ve added the following code (though this was via the Code Snippets plugin, so not sure if that could be an issue too), and would like to know a) if everything looks correct (it seems to work ok), b) if theme or WP updates will affect this code? c) if I should enter the code directly into a file myself?
I just want to make sure there are no issues with it down the track, and any entries entered into these custom types won’t be lost. Thanks so much! (also the site is under construction so not live)
Here’s the code:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( ‘Portfolio’,
// CPT Options
array(
‘labels’ => array(
‘name’ => __( ‘Portfolio’ ),
‘singular_name’ => __( ‘Portfolio’ )
),
‘public’ => true,
‘has_archive’ => false,
‘rewrite’ => array(‘slug’ => ‘work’),
)
);
}
// Hooking up our function to theme setup
add_action( ‘init’, ‘create_posttype’ );
/* Custom Post Type End */part two:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( ‘Portfolio’,
// CPT Options
array(
‘labels’ => array(
‘name’ => __( ‘Portfolio’ ),
‘singular_name’ => __( ‘Portfolio’ )
),
‘public’ => true,
‘has_archive’ => false,
‘rewrite’ => array(‘slug’ => ‘work’),
)
);
}
// Hooking up our function to theme setup
add_action( ‘init’, ‘create_posttype’ );
/* Custom Post Type End */August 17, 2020 at 4:00 am #1405925David
StaffCustomer SupportHi there,
looks ok to me.
Theme and WP updates won’t affect that code whilst it is saved in your Code Snippets.August 17, 2020 at 5:05 pm #1406964Sophie
Hi David, thanks for getting back to me so quickly! Would I be better adding this into the functions.php file instead?
August 18, 2020 at 2:14 am #1407345David
StaffCustomer SupportIn your Child Themes functions.php would be the best place for it.
Don’t add it to the parent theme functions.phpAugust 18, 2020 at 7:00 pm #1408676Sophie
Got it! Thanks for your help 🙂
August 19, 2020 at 1:43 am #1409009David
StaffCustomer SupportAwesome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.