WordPress.org

Ready to get started?Download WordPress

Forums

WordPress HTTPS (SSL)
[resolved] Force SSL on old posts (7 posts)

  1. pv2008
    Member
    Posted 1 year ago #

    Hi,

    I was wondering what is the recommended way of enforcing SSL on old posts, i.e. posts or pages which have been published before the plugin has been installed? I have over 100 posts/pages and it will be quite a pain to have to tick the checkbox for all of them.

    Thanks!

    http://wordpress.org/extend/plugins/wordpress-https/

  2. pbassham
    Member
    Posted 1 year ago #

    Yes, this would be good to know.

  3. joe.toomey
    Member
    Posted 1 year ago #

    If you want all posts to be SSL only, just don't check the box the says Force SSL Exclusively. I think this option is unfortunately named, b/c I thought it would do the opposite of what it actually does, but the description on the right side of the checkbox is accurate ("Posts and pages without Force SSL enabled will be redirected to HTTP").

  4. pv2008
    Member
    Posted 1 year ago #

    Hi Joe,

    Yes, I have kept the option you mentioned unchecked.

    The current situation is that if I started off with https on any page/post/"home" page, links to all the posts do start with https so everything is working as expected. Now, if I happen to type in http://domain.com it I will automatically get redirected to https://domain.com (by the plugin I presume) which is also what I expected. However, there is no automatic redirection from http to https for posts/pages, unless I check the option to have https for individual pages. Is THIS the expected behaviour too? I mean, should I be doing this using a redirection plugin instead??

    Thanks.

  5. Mvied
    Member
    Plugin Author

    Posted 1 year ago #

    If you want to make your whole site HTTPS, change your Site URL to contain HTTPS.

    Currently the only option for mass-updating posts is writing some custom code to do so.

    $args = array(
    	'numberposts' => -1
    );
    $posts = get_posts($args);
    foreach( $posts as $post ) {
    	update_post_meta($post->ID, 'force_ssl', '1');
    }
  6. andyhung
    Member
    Posted 1 year ago #

    hi Mvied,

    $args = array(
    'numberposts' => -1
    );
    $posts = get_posts($args);
    foreach( $posts as $post ) {
    update_post_meta($post->ID, 'force_ssl', '1');
    }

    if i want to enforcing SSL on old posts every time I activate this plugin, where should i put these codes in wordpress-https.php?

    thanks

  7. Mvied
    Member
    Plugin Author

    Posted 1 year ago #

    This should work. Just put it in your theme's functions.php or in your own plugin file.

    register_activation_hook( 'wp-content/wordpress-https/wordpress-https.php', 'wordpress_https_activate' );
    
    function wordpress_https_activate() {
    	$args = array(
    		'numberposts' => -1
    	);
    	$posts = get_posts($args);
    	foreach( $posts as $post ) {
    		update_post_meta($post->ID, 'force_ssl', '1');
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic