phpwordpresscustom-post-typeelementor

Display CPT text content inside an elementor popup


I'm working on an elementor layout that will be used as a template for a custom post type that will hold all the projects of a designer. Since for each project there is a lot of text, I'm thinking to have an offcanvas popup that will display the text of the current displayed project. The mai problem is that Elementor will not give me the ability to select the post content widget when I create a new popup. I'm not sure if this is possible.

Is there any way to get the current post content using an hook or a filter and display it using a shortcode or with another method?


Solution

  • Step 1: Create a Custom Shortcode

    Add the following code to your theme’s functions.php file or a custom plugin to create a shortcode that fetches the post content:

    function my_custom_post_content_shortcode() {
      global $post;
      return apply_filters('the_content', $post->post_content);
    }
    add_shortcode('custom_post_content', 'my_custom_post_content_shortcode');
    

    Step 2: Insert the Shortcode in Elementor Popup

    1. Create a Popup: Go to Templates > Popups in WordPress, create a new popup with Elementor.
    2. Use Text Editor Widget: Drag a Text Editor widget into the popup and insert the shortcode [custom_post_content].

    Step 3: Trigger the Popup

    Edit CPT Template: Open the template for editing in Elementor.

    Add Button/Link: Place a button or link element on the page.

    Configure Action: In the link settings, set the action to open the popup (Dynamic Tags > Actions > Popup).