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

移除href属性值为#的WordPress活动预约按钮

Fix: Hide WordPress Register Buttons When href is "#"

Hey Vanessa, no worries—this is a common tweak and we can get it sorted quickly. Here are three solid solutions depending on how comfortable you are with code:

1. Quick CSS Fix (Easiest)

If your theme adds a consistent class to the Register buttons (like register-button), you can use CSS attribute selectors to hide any button with href="#. Just add this code to your WordPress site's custom CSS:

/* Hide Register buttons that link to # */
a.register-button[href="#"] {
    display: none !important; /* Use !important if needed to override theme styles */
}

How to add this:

  • Go to your WordPress Dashboard → Appearance → Customize → Additional CSS
  • Paste the code there and hit Publish

This works for most static schedules. If your events load dynamically (like via AJAX), move to the next solution.

2. JavaScript for Dynamic Content

If your schedule loads events after the page initializes (e.g., filtering, pagination), CSS might not catch the buttons. Use this JavaScript to check and hide them after content loads:

// Run after the page and all dynamic content is ready
document.addEventListener('DOMContentLoaded', function() {
    // Target all Register buttons with href="#"
    const hiddenButtons = document.querySelectorAll('a.register-button[href="#"]');
    
    // Hide each one
    hiddenButtons.forEach(btn => {
        btn.style.display = 'none';
        // Optional: Remove the button entirely instead of hiding it
        // btn.remove();
    });
});

How to add this:

  • Go to Appearance → Customize → Widgets → Add a Custom HTML widget to your Footer area
  • Paste the code inside <script> tags (like <script>[code here]</script>)
  • Save changes

3. Theme Template Edit (Most Permanent)

If you want to stop the button from being output entirely (instead of just hiding it), edit your theme's template file where the Register button is generated.

  1. Find the template file: Look in your theme's folder for files like event-schedule.php, single-event.php, or a template part for events.
  2. Locate the button code: It’ll look something like this (varies by theme):
    <a href="<?php echo get_post_meta(get_the_ID(), 'event_register_url', true); ?>" class="register-button">Register</a>
    
  3. Add a condition to skip output if href is #:
    <?php
    $register_url = get_post_meta(get_the_ID(), 'event_register_url', true);
    // Only show the button if the URL exists and isn't #
    if (!empty($register_url) && $register_url !== '#') : ?>
        <a href="<?php echo esc_url($register_url); ?>" class="register-button">Register</a>
    <?php endif; ?>
    

Note: Use a child theme to edit templates—this way your changes won’t get overwritten when the parent theme updates.

Pick the solution that fits your skill level and site setup. Let me know if you need help locating the right template file or class name!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:31:23