skip to Main Content

WordPress Divi Theme shortcode adding problem

My Divi version is 3.20.1. I am trying to add my own custom shortcode in the website. However, when I add this shortcode, the elements displayed using this shortcode appear both in the “Edit page” area top section besides the main page.

add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
function lantry_btx_fun_Main_Page_Show_Testimonial(){
     include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php"; 
}

My question is, how can I remove this from the “Edit page” section ??

I provided some screenshot.

Divi module Image Option Select
Show top of the post page


When I remove Divi this problem will be solved. But I need to use Divi.

3

Answers


  1. You can check if a adminuser is logged in and if not execute your function hope this helps but now you have to always log out or use incognito mode to see if its there:

    add_shortcode( "Btx_Show_Testimonial_Main_Page", 'lantry_btx_fun_Main_Page_Show_Testimonial');
    function lantry_btx_fun_Main_Page_Show_Testimonial(){
         if (current_user_can( 'update_core' )) {
              return;
          }
         include_once LANTRY_BITECHX_SHORTCODE_DIR_PATH."views/Main_Page_testimonial_show.php"; 
    }    
    Login or Signup to reply.
  2. I don’t think the problem comes from DIVI but from your shortcode. Please attach the content of your file Main_Page_testimonial_show.php

    The shortcode callback shouldn’t produce an output but should return the result.

    You can find this on documentation website here. Please pay attention to

    Note that the function called by the shortcode should never produce an
    output of any kind. Shortcode functions should return the text that is
    to be used to replace the shortcode. Producing the output directly
    will lead to unexpected results. This is similar to the way filter
    functions should behave, in that they should not produce expected side
    effects from the call since you cannot control when and where they are
    called from.

    Login or Signup to reply.
  3. Here, simply you can create the shortcode in the functions.php file and on your Page/Posts you can use the Text Module and add the [shortcode].

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search