如何移除WordPress指定页面自定义模板中的作者信息框?
Hey Dave, let's walk through how to safely remove that author info box from your custom page template. I've got a few solid methods depending on your site's setup:
Method 1: Remove via Template File Edit (Permanent, Recommended for Security)
If you want to fully eliminate the author box code from the page (best for strict security needs):
- Locate your new custom page template file (usually named something like
page-custom-template.phpin your theme's directory) - Open the file in a code editor, then search for code blocks related to the author info box. Look for identifiers like:
- Functions such as
get_author_meta() - Template part calls like
get_template_part( 'parts/author-box' ) - HTML elements with classes like
author-infoorauthor-box
- Functions such as
- Delete the entire code block responsible for rendering the author box
- Critical note: Always make a backup of the template file before making changes—this lets you revert if something goes wrong
- Save the file, upload it to your server (if working remotely), and refresh the page to confirm the author box is gone
Method 2: Hide with CSS (Quick Fix)
If you need a fast temporary solution or don't want to edit template code right now:
- Use your browser's developer tools (press F12, then use the element picker to select the author info box) to find its unique CSS class or ID (e.g.,
.author-info-box) - Open your theme's customizer (under Appearance > Customize in most CMS platforms) or edit your theme's
style.cssfile - Add this CSS rule, replacing the class with the one you found:
.author-info-box { display: none !important; }
- Save your changes and refresh the page. The author box will no longer be visible.
- Heads up: This only hides the box visually—the code still exists in the page source. For true security-focused removal, go with Method 1.
Method 3: Remove via Code Snippet (CMS-Specific)
If your site uses a CMS like WordPress and you prefer not to edit the template directly:
- Install and activate a code snippet management plugin (there are free, reputable options available)
- Create a new PHP snippet and add code like this, adjusting it to match your theme's actual author box hook/function:
function remove_target_page_author_box() { // Check if we're on the specific page you're working on if ( is_page( 'how-to-get-a-girlfriend' ) ) { // Replace 'theme_render_author_box' with your theme's actual author box function remove_action( 'after_page_content', 'theme_render_author_box' ); } } add_action( 'wp', 'remove_target_page_author_box' );
- Activate the snippet, then refresh the page to verify the author box is removed.
内容的提问来源于stack exchange,提问作者Dave J
相关产品推荐
相关产品推荐

