Skip to content

Wordpress Tricks

Change Wordpress Site URL using wp-config.php

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

Change a password with just phpMyAdmin

When moving sites from "Managed Wordpress" GoDaddy hosting to a proper hosting plan, you lose the ability to one click login to WordPress. That led me to quite frequently realize that I actually don't have the admin password. To solve this

  • Open phpMyAdmin
  • Navigate to the database for your site, then the xxxxx_users table
  • Edit the user you wish to change, replacing the password field with whatever password you want
  • Change the "type" to MD5 so it hashes properly
  • Hit go and you're done!

Disable comments after the fact

Maybe you forgot to disable comments when you set up your site and now have a ton of spam. A simple way to solve this is to do the following:

  • Select all posts and pages
  • Bulk edit
  • Click comments, then 'do not allow comments'
  • Next, settings -> discussion
  • Disable comments on new posts

Now all comments are disabled!

Move a huge blog

Lots of times I have run into the issue of moving a massive blog filled with images and featured images to a new site. Wordpress importer claims to move images but clearly does not. To solve this issue, we are using two plugins

  1. Export media with selected content
  2. Velvet blues update url

Simply export the ENTIRE Wordpress posts section using no settings whatsoever. Do not change the date range, do not choose the author, do not pass go and do not collect $200. Then, click the checkbox at the bottom that says "export media with selected content". Simply upload this to your new site and use the wordpress importer. Choose "import media" and let it run. Then import it again. And again. And maybe one more time for good measure. Each time you will get errors about "media already exists"; this is good because it shows that you are bypassing the parts that have been already updated and moving to the non-uploaded images (php and webservers have a max time to process requests, so if the blog is large enough it will time out eventually!)

Then, run velvet blues with the old URL and new URL to make sure all of the posts are updated!

Solve broken symbols (squares/? diamond)

Simply change the post type to basic and back to post name. This change will do something on the back end that miraculously fixes it.

Turn off pesky PHP warnings

wp-config.php

ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

Auto Archive Posts After a Certain Date

functions.php

// Add a custom interval of 1 minute
add_filter('cron_schedules', 'add_custom_cron_interval');
function add_custom_cron_interval($schedules) {
    $schedules['oneminute'] = array(
        'interval' => 60, // Interval in seconds (300 seconds = 5 minutes)
        'display'  => esc_html__('Every minute for testing'),
    );
    return $schedules;
}


// Schedule an event if it's not already scheduled -- change to daily if not testing
if (!wp_next_scheduled('update_custom_post_status')) {
    wp_schedule_event(time(), 'oneminute', 'update_custom_post_status');
}


// Hook into that event that will fire daily
add_action('update_custom_post_status', 'change_post_status_after_x_days');

function change_post_status_after_x_days() {
    $x_days_ago = date('Y-m-d', strtotime('-30 days')); // Change 30 to the number of days

    $args = array(
        'post_type'      => 'notifications', // Replace with your custom post type
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'date_query'     => array(
            array(
                'before' => $x_days_ago,
            ),
        ),
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $post_id = get_the_ID();

            // Change post status
            $updated_post = array(
                'ID'          => $post_id,
                'post_status' => 'archive', // New status
            );

            // Update the post
            wp_update_post($updated_post);
        }
    }

    wp_reset_postdata();
}

Replace Elementor Twitter Icon with X

functions.php

add_filter( 'elementor/widget/render_content', function($output){
    // replace the
    $re = '/(<svg[^>]+class="[^"]*e-fab-twitter".*?<path\s+d=")(.+?)(".+?<\/svg>)/s';
    $output = preg_replace_callback($re, function($matches){
        $path = "M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z";
        return $matches[1].$path.$matches[3];
    }, $output);
    return $output;
}, 10, 2 );

Revisions not enabled/visible/working

wp-config.php

define( 'WP_POST_REVISIONS', TRUE );