WordPress后台显示短代码问题求助:前端正常后台出现et_pb_section内容
Fix: Prevent Shortcode from Showing in WordPress Admin
Got it, let's sort out this issue where your Elementor global module shortcode is showing up in the WordPress admin. Here's what's going wrong and how to fix it:
The Problem
Your current code doesn't distinguish between the frontend and admin area, and you're manually calling do_action('wp_footer')—this causes the hook to fire in the admin too, which outputs the shortcode content you don't want to see there.
The Solution
Modify your code to only run the output on the frontend, and remove the unnecessary manual hook call:
<?php function cta_fixed() { // Only execute this on the frontend (not admin) if ( !is_admin() ) { echo do_shortcode('[et_pb_section global_module="2893"][/et_pb_section]'); } } add_action( 'wp_footer', 'cta_fixed' ); // Remove the manual do_action call—WordPress triggers this hook automatically ?>
Key Changes Explained
!is_admin()Check: This conditional ensures your shortcode output only runs when the user is viewing the frontend of your site. The admin area will skip this code entirely.- Removed Manual
do_action('wp_footer'): WordPress already fires thewp_footerhook at the correct point in the page lifecycle (both frontend and admin). Calling it manually forces an extra execution, which was part of why the shortcode showed up in the admin.
This tweak will keep your frontend working as expected while hiding the shortcode content from the WordPress admin.
内容的提问来源于stack exchange,提问作者Mark Hendriksen
相关产品推荐
相关产品推荐

