Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Last active October 5, 2018 13:31
Show Gist options
  • Save BinaryMoon/a5dd78526baf89dbbf84a3d59be4d725 to your computer and use it in GitHub Desktop.
Save BinaryMoon/a5dd78526baf89dbbf84a3d59be4d725 to your computer and use it in GitHub Desktop.
Add a text widget to the recent posts column on the Opti Homepage.
<?php
/**
* Plugin Name: Opti Recent Posts Intro
* Plugin URI: https://prothemedesign.com
* Description: Use a widget to add an intro to the recent posts column.
* Author: Ben Gillbanks
* Version: 1.0
* Author URI: https://prothemedesign.com
*/
function opti_recent_posts_intro() {
?>
<script>
jQuery( document ).ready(
function() {
var $ = jQuery;
var widget_id = '#text-8';
// Move widget contents to above lead story element.
if ( $( '#lead-story' ).length > 0 ) {
$( widget_id + ' .textwidget' ).addClass( 'recent-posts-intro' ).insertBefore( '#lead-story' );
}
// Delete old widget.
// This will work on all pages.
$( widget_id ).remove();
}
);
</script>
<?php
}
add_action( 'wp_footer', 'opti_recent_posts_intro', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment