Created
June 13, 2016 15:34
-
-
Save wisecrab/96e02ac8ec3ca77b919f817c1f18c2f4 to your computer and use it in GitHub Desktop.
A simple script to add an expanding "read more" button to your page content on WordPress using a shortcode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************** | |
>> Read More Shortcode << | |
**************************************************/ | |
jQuery(document).ready(function() { | |
//Set the content area as a variable | |
var moreContent = jQuery('.read_more_content'); | |
//Auto hide the hidden content by default | |
moreContent.slideUp(); | |
}); | |
function readMoreToggle( revealButton ) { | |
var moreContent = revealButton.prev('.read_more_content'); | |
if( moreContent.hasClass('open') ) { | |
var $button_text = revealButton.attr('data-expand'); | |
moreContent.slideUp().removeClass('open'); | |
revealButton.text($button_text); | |
} else { //If the content is not showing | |
var $button_text = revealButton.attr('data-contract'); | |
moreContent.slideDown().addClass('open'); | |
revealButton.text($button_text); | |
} | |
} | |
jQuery('.revealContent').click(function() { | |
readMoreToggle( jQuery(this) ); | |
}); | |
jQuery(document).ready(function() { | |
jQuery('.us_button').removeClass('us_native'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* //////////////////////////////////////////////////////////////////////////////////////// | |
// Read More Shortcode \\ | |
//////////////////////////////////////////////////////////////////////////////////////// */ | |
//add [read_more]...[/read_more] shortcode | |
function shortcode_read_more($atts, $content=null) { | |
$more_content = '<div class="read_more_content">'; | |
$more_content.= $content; | |
$more_content.= '</div>'; | |
return $more_content; | |
} | |
add_shortcode('read_more', 'shortcode_read_more'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment