Skip to content
Help Center
  • Pricing
  • ProductsExpand
    • Premium BundlesGet all the tools you need in one bundle
    • Kadence ThemeLightning-fast performance theme for modern websites
    • Kadence BlocksDrop in ready designs with advanced controls for pixel perfect websites
    • Kadence Shop KitCreate a more effective WooCommerce shopping experience
    • Kadence ConversionsBoost sales and build engaged audiences with popups and banners
    • Kadence InsightsEasily create A/B tests. Optimize your pages to drive higher conversions.
    • View All Products
  • AI Starter Templates
  • Blog
  • SupportExpand
    • Help CenterProduct Questions? Not sure how to do something? Start here
    • Support TicketsNeed help? We love to help our customers
    • About usCrafted with love in Missoula, Montana
    • Contact usPre Sale Questions? Need help purchasing?
Account Account
Get Kadence
Kadence Theme
  • Features
  • Pro
  • Starter Templates
  • HelpExpand
    • Documentation
    • Facebook Group
    • Submit a Ticket
    • Feature Requests
    • Roadmap
    • Changelog
Help Center
Kadence Theme

Kadence Theme

  • Create a Full Screen Landing Page

Getting Started

  • Theme Installation
  • Getting Started with a Classic Starter Template

Customize Settings

  • How to customize the Kadence Footer
  • Responsive Breakpoints in Kadence
  • How to Import, Export, and Reset Kadence Theme Customizer Settings Using Starter Templates Plugin
  • How to use the Kadence Theme Color Palette
  • Typography and setting font sizes for different devices
  • How to setup Page/Post settings
  • How to Add a Sidebar
  • Sticky Sidebars
  • How to style Buttons
  • How to add Scroll To Top

Header

  • How to Customize the Kadence Header
  • Customizing the Mobile Navigation Area
  • How to Use a Transparent Header
  • Customizing the Topbar
  • Navigation Colors (Transparent Header, Sticky Header)
  • Edit Dropdown Menu Styling
  • Working with the Sticky Header
  • Social Media Icons in the Header
  • Editing a Row in the Header

General WordPress

  • Set Site Favicon
  • How do I add Custom CSS
  • Adding Google Analytics
  • How to backup my site?
  • How to add a Custom Post Type
  • Fix: Page Not Updating
  • How to Find the Page or Post ID
  • How to prevent spam comments
  • How do I turn off comments?
  • How to Remove All Spam Comments

Troubleshooting

  • Troubleshooting the “Update Failed: Service Unavailable” error when updating Pro Kadence WP plugins
  • How to Enable the WordPress Error Logs
  • WordPress Error “Incompatible Archive”
  • Temporarily deactivating plugins
  • How to View Console Log Errors
  • Clearing Your Website Cache
  • How to preview the mobile version of your site on Desktop
  • Getting 500 error
  • Broken Styles after version 1.1.15

Advanced

  • Common Code Snippets for Kadence Users
  • How to translate using LocoTranslate
  • How to hook elements inside of post or page content
  • What Is a Child Theme, Should I install one, if so How?
  • How to add a custom filter or function with Code Snippets
  • Adding Custom Fonts to Kadence
  • How to make a custom 404 page
  • How to change a theme icon to something custom
  • Change any text on your site
  • Changing Various Heading HTML Tags
  • Adding Google Tag Manager with a child theme or code snippet plugin
  • Replace Author HTML (Multiple Author Support)
  • Theme hooks

Pro Addon

  • Kadence Maintenance Mode
  • WooCommerce Addons
  • How to Display Custom Post Types with Kadence Elements Templates and the Post/Grid Carousel
  • How to use conditional header
  • Theme hooks
  • Kadence Theme Pro Plugin
  • Header Addons
  • How to create a Mega (multicolumn menu)
  • How to add contact information
  • How to add a toggle open menu for desktop
  • How to use the Color Palette Switch (Dark Mode)
  • How to add a login and account Menu
  • Kadence Custom Fonts
  • How to add scripts in header/footer
  • How to open the side cart when a product is added to cart
  • How to use Element Hooks

Kadence Elements

  • What is Kadence Elements?
  • Installing Kadence Elements
  • The Four Types of Kadence Elements
  • Switching between different Kadence Elements Types
  • Showing/Hiding Kadence Elements Settings
  • How to Create a Kadence Elements Content Section
  • Creating a Template Element
  • What goes into an element?
  • How to Replace the Footer Using a Kadence Element
  • How to Use an Element to Replace the Archive Loop Item Content
  • How to Design a Post Grid/Carousel using a Kadence Element

Woocommerce

  • How to Add Image Switch on Hover for Product Archives
  • How to Add a Mini Cart to the Site Header
  • How to Change the WooCommerce Product Loop Title Tags
  • Home
  • Knowledge Base
  • Kadence Theme
  • Kadence Theme
  • Advanced

Common Code Snippets for Kadence Users

Are you a Kadence theme user looking to enhance your WordPress site with powerful customizations? Look no further! In this article, we’ve compiled a collection of essential code snippets tailored specifically for Kadence users. Whether you want to customize your admin experience, optimize site performance, or add new functionality without relying on additional plugins, these snippets will help you unlock new possibilities and streamline your workflow. Dive in to discover how you can easily implement these snippets to make the most out of your Kadence-powered website.

You can add PHP code to your site using a plugin like Code Snippets or your functions.php file (in a child theme).

Disable the WordPress Admin Bar for All Users Except Administrators:

if (!current_user_can('administrator')) {
    add_filter('show_admin_bar', '__return_false');
}

Add Google Analytics:

function add_google_analytics() {
    echo "<script async src='https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_ID'></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'YOUR_TRACKING_ID');
    </script>";
}
add_action('wp_head', 'add_google_analytics');

Change the Excerpt Length:

function custom_excerpt_length($length) {
    return 20; // Change 20 to the number of words you want in the excerpt
}
add_filter('excerpt_length', 'custom_excerpt_length', 999);

Redirect Users After Login:

function custom_login_redirect($redirect_to, $request, $user) {
    if (isset($user->roles) && is_array($user->roles)) {
        if (in_array('administrator', $user->roles)) {
            return admin_url(); // Redirect administrators to the dashboard
        } else {
            return home_url(); // Redirect other users to the homepage
        }
    }
    return $redirect_to;
}
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

Customize Kadence Logo Redirect Link

function custom_kadence_logo_url() {
    return 'https://example.com';
}
add_filter( 'kadence_logo_url', 'custom_kadence_logo_url' );

Customize the Login Page Logo URL:

function custom_login_logo_url() {
    return home_url();
}
add_filter('login_headerurl', 'custom_login_logo_url');

Custom Login Logo:

function custom_login_logo() {
    echo '
    <style type="text/css">
        #login h1 a {
            background-image: url(' . get_stylesheet_directory_uri() . '/images/custom-logo.png) !important;
            background-size: contain !important;
            width: 100% !important;
        }
    </style>';
}
add_action('login_head', 'custom_login_logo');

Add Custom Image Sizes:

function custom_image_sizes() {
    add_image_size('custom-size', 800, 600, true); // Custom size with crop
}
add_action('after_setup_theme', 'custom_image_sizes');

Allow SVG Uploads:

function custom_mime_types($mimes) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'custom_mime_types');

Add a Custom User Role:

function add_custom_user_role() {
    add_role('custom_role', 'Custom Role', array(
        'read' => true,
        'edit_posts' => false,
    ));
}
add_action('init', 'add_custom_user_role');

Add Custom Dashboard Message:

function custom_dashboard_message() {
    echo '<div class="notice notice-success is-dismissible">
        <p>Welcome to your custom WordPress dashboard!</p>
    </div>';
}
add_action('admin_notices', 'custom_dashboard_message');

Customize Footer Text in WordPress Admin:

function custom_admin_footer() {
    echo 'Your custom footer text here.';
}
add_filter('admin_footer_text', 'custom_admin_footer');

Changes the Kadence theme Next/Previous buttons to only show posts in the same category as the current post:

// Add a filter to modify the arguments for post navigation
add_filter('kadence_post_navigation_args', function($args) {
    // Set the 'in_same_term' argument to true, ensuring navigation is limited to posts in the same category or taxonomy term
    $args['in_same_term'] = true;
    
    // Return the modified arguments
    return $args;
});

Changes the number of posts per page for the blog archive:

// Hook into the 'pre_get_posts' action
add_action('pre_get_posts', 'modify_blog_loop_query');
// Function to modify the main query
function modify_blog_loop_query($query) {
    // Check if it is the main query and not an admin page
    if ($query->is_main_query() && !is_admin()) {
        // Check if this is the blog page (home) or an archive page
        if ($query->is_home() || $query->is_archive()) {
            // Set the number of posts to 20
            $query->set('posts_per_page', 20);
        }
    }
}

Creates a custom placeholder for the Kadence WooCommerce Email Designer:

// Add a filter to modify the WooCommerce email order body text in Kadence
add_filter('kadence_woomail_order_body_text', function($body, $order) {
    // Replace the custom placeholder with specific custom text in the email body
    $body_text = str_replace('{custom_placeholder}', 'Custom text for placeholder.', $body);
    
    // Return the modified email body text
    return $body_text;
}, 15, 2);

Redirect Old URL to New URL:

function custom_redirect_old_to_new() {
    if (is_page('old-page')) {
        wp_redirect(home_url('/new-page'), 301);
        exit();
    }
}
add_action('template_redirect', 'custom_redirect_old_to_new');

Add Custom Body Class:

function custom_body_class($classes) {
    if (is_single()) {
        $classes[] = 'custom-single-class';
    }
    return $classes;
}
add_filter('body_class', 'custom_body_class');
How to translate using LocoTranslate
  • Pricing
  • Products
    • Premium BundlesGet all the tools you need in one bundle
    • Kadence ThemeLightning-fast performance theme for modern websites
    • Kadence BlocksDrop in ready designs with advanced controls for pixel perfect websites
    • Kadence Shop KitCreate a more effective WooCommerce shopping experience
    • Kadence ConversionsBoost sales and build engaged audiences with popups and banners
    • Kadence InsightsEasily create A/B tests. Optimize your pages to drive higher conversions.
    • View All Products
  • AI Starter Templates
  • Blog
  • Support
    • Help CenterProduct Questions? Not sure how to do something? Start here
    • Support TicketsNeed help? We love to help our customers
    • About usCrafted with love in Missoula, Montana
    • Contact usPre Sale Questions? Need help purchasing?
Account Login
  • Features
  • Pro
  • Starter Templates
  • HelpExpand
    • Documentation
    • Facebook Group
    • Submit a Ticket
    • Feature Requests
    • Roadmap
    • Changelog