22

How to Force SSL on Custom Post Types in WordPress

Powered by WPCodeBox

This WordPress snippet helps you force an SSL connection on single pages of custom post types (like movies and books) to enhance security. It’s adaptable for specific page IDs or author archives, ensuring your custom content remains secure.


<?php

/** 
 * Snippet Name: Force SSL on custom post types 
 * Snippet URL: https://wpcustoms.net/snippets/force-ssl-custom-post-types/ 
 */  
function wpc_force_ssl_cpt( $force_ssl,  $url = '' ) {    
    if ( is_singular( array( 'movies', 'book' ) ) ) {  
        return true;
    }  
    
    return $force_ssl;  
}  
add_filter('force_ssl' , 'wpc_force_ssl_cpt', 10, 3);

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.