You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MH Magazine Lite主题插件广告插入问题:广告显示在特色图下方而非标题下方

Fix: Ad Showing Below Featured Image Instead of Post Title in MH Magazine Lite

Hey there! Let's get that ad positioned right below your post title where you want it. The issue here is that you're probably hooking into a spot that fires after the featured image loads—let's adjust that with the theme's built-in hooks, or a quick child theme tweak if needed.

MH Magazine Lite has a handy action hook that fires right before the featured image loads, which is exactly after the post title and meta info. Here's how to use it in your plugin:

  1. Add this code to your plugin file:
function display_ad_below_title() {
    // Only show the ad on single post pages
    if (is_single()) {
        ?>
        <div class="ad-below-post-title" style="margin: 1.5rem 0; padding: 1rem; border: 1px solid #eee;">
            <!-- Replace this with your actual ad code (e.g., Google AdSense, custom banner) -->
            <p>Your Ad Content Goes Here</p>
        </div>
        <?php
    }
}
// Hook into the spot right before the featured image
add_action('mh_before_featured_image', 'display_ad_below_title');

This hook is part of the theme's mh_featured_image() function, so it will render your ad immediately after the post title/meta section, and before the featured image—perfect for your needs.

Option 2: Add a Custom Hook (If the Built-in One Doesn't Exist)

If for some reason your version of MH Magazine Lite doesn't have the mh_before_featured_image hook, use a child theme to add your own custom hook (never modify the parent theme directly—updates will erase your changes):

  1. Create and activate a child theme for MH Magazine Lite.
  2. Copy the single.php file from the parent theme to your child theme folder.
  3. Open the child theme's single.php and find this section:
<header class="entry-header">
    <?php mh_post_title(); ?>
    <?php mh_post_meta(); ?>
</header>
<?php mh_featured_image(); ?>
  1. Insert a custom action hook right before closing the header:
<header class="entry-header">
    <?php mh_post_title(); ?>
    <?php mh_post_meta(); ?>
    <!-- Custom hook for ad placement -->
    <?php do_action('mh_after_post_header'); ?>
</header>
<?php mh_featured_image(); ?>
  1. Now update your plugin code to use this new hook:
function display_ad_below_title() {
    if (is_single()) {
        ?>
        <div class="ad-below-post-title">
            <!-- Your ad code here -->
        </div>
        <?php
    }
}
add_action('mh_after_post_header', 'display_ad_below_title');

Quick Tips

  • Adjust the CSS class ad-below-post-title to style your ad spacing, borders, etc., to match your theme.
  • If you notice other elements loading before/after your ad, tweak the priority in add_action (e.g., add_action('mh_before_featured_image', 'display_ad_below_title', 5);—lower numbers run earlier).

内容的提问来源于stack exchange,提问作者Kenyis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:55:09