Last updated on October 18, 2023

Elementor custom post type support

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Enable custom post type support in Elementor.

Elementor is a popular page builder plugin for WordPress that allows users to create custom layouts and designs for their website. By default, Elementor supports the regular WordPress post types such as posts and pages. However, there may be cases where you want to use Elementor with custom post types that you have created.

To add Elementor support for a custom post type, you can use the elementor/theme/register_post_type filter. This filter allows you to modify the list of post types that Elementor supports.

Here’s an example code snippet that demonstrates how to add Elementor support for a custom post type named “portfolio”:

function wpsnippets_add_elementor_support_for_portfolio() {
    add_theme_support( 'elementor', array( 'portfolio' ) );
}
add_action( 'elementor/theme/register_post_type', 'wpsnippets_add_elementor_support_for_portfolio' );

In the code snippet above, we define a custom function wpsnippets_add_elementor_support_for_portfolio that adds Elementor support for the “portfolio” post type. We use the add_theme_support function with the 'elementor' feature and pass an array containing the custom post type name.

By adding this code to your theme’s functions.php file or a custom plugin, Elementor will now be available for use with the “portfolio” post type. You will be able to design custom layouts for your portfolio items using Elementor’s intuitive drag-and-drop interface.

This code snippet can be useful in scenarios where you have created custom post types and want to leverage the power of Elementor to design their layouts. It allows you to extend Elementor’s capabilities beyond the default post types and create visually appealing designs for your custom content.

Examples

Example 1: Adding Elementor support for a custom post type

This example demonstrates how to add Elementor support for a custom post type in WordPress. By adding Elementor support, you enable the use of Elementor templates for the custom post type.

add_action( 'elementor/theme/register_locations', 'wpsnippets_add_elementor_support_for_custom_post_type' );

function wpsnippets_add_elementor_support_for_custom_post_type( $locations ) {
    $locations['custom_post_type'] = [
        'label' => __( 'Custom Post Type', 'text-domain' ),
        'edit_in_content' => true,
    ];

    return $locations;
}

In this code example, we use the elementor/theme/register_locations action hook to add Elementor support for a custom post type. We define a new location for the custom post type, specifying a label and enabling the ability to edit the content within Elementor.

Example 2: Removing Elementor support for a custom post type

This example demonstrates how to remove Elementor support for a custom post type in WordPress. By removing Elementor support, you disable the use of Elementor templates for the custom post type.

add_action( 'elementor/theme/register_locations', 'wpsnippets_remove_elementor_support_for_custom_post_type' );

function wpsnippets_remove_elementor_support_for_custom_post_type( $locations ) {
    unset( $locations['custom_post_type'] );

    return $locations;
}

In this code example, we use the elementor/theme/register_locations action hook to remove Elementor support for a custom post type. We unset the location for the custom post type, effectively disabling the use of Elementor templates for it.

Example 3: Modifying Elementor support for a custom post type

This example demonstrates how to modify Elementor support for a custom post type in WordPress. By modifying Elementor support, you can customize the label and other settings for the custom post type location in Elementor.

add_action( 'elementor/theme/register_locations', 'wpsnippets_modify_elementor_support_for_custom_post_type' );

function wpsnippets_modify_elementor_support_for_custom_post_type( $locations ) {
    $locations['custom_post_type']['label'] = __( 'Modified Custom Post Type', 'text-domain' );

    return $locations;
}

In this code example, we use the elementor/theme/register_locations action hook to modify Elementor support for a custom post type. We update the label for the custom post type location, changing it to “Modified Custom Post Type” in Elementor.

Last updated on October 18, 2023. Originally posted on November 16, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *