Skip to content

Instantly share code, notes, and snippets.

View kirandash's full-sized avatar

Kiran Dash kirandash

View GitHub Profile
@kirandash
kirandash / Excerpt limit
Last active April 25, 2017 08:30
This function is used to limit the excerpt and customize it.
//EXCERPT LIMIT
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 300);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
return $excerpt.' ...';
@kirandash
kirandash / Dynamically populate a select fields choices in ACF
Created July 7, 2016 11:52
Use the code snippet to dynamically populate a select field's choices in ACF.
//dynamically populate a select fields choices
function acf_load_category_field_choices( $field ) {
// reset choices
$field['choices'] = array();
// get the textarea value from options page without any formatting
$choices = get_categories();
@kirandash
kirandash / Set bloginfo with two different colors
Created July 8, 2016 07:36
Set bloginfo with two different colors. Wrap the first word of the blog title with the <span>...</span> tag.
//Set bloginfo with two different colors
/**
* Wrap the first word of the blog title with the <span>...</span> tag.
* Assumes the Twenty Twelve theme.
*
* @see http://stackoverflow.com/a/25096093/2078474
*/
add_filter( 'body_class',
function( $class )
@kirandash
kirandash / Adding a slide effect to bootstrap dropdown
Created July 8, 2016 07:38
Adding a slide effect to bootstrap dropdown
// ADD SLIDEDOWN ANIMATION TO DROPDOWN //
$('.dropdown').on('show.bs.dropdown', function(e){
$(this).find('.dropdown-menu').first().stop(true, true).slideDown();
});
// ADD SLIDEUP ANIMATION TO DROPDOWN //
$('.dropdown').on('hide.bs.dropdown', function(e){
$(this).find('.dropdown-menu').first().stop(true, true).slideUp();
});
jQuery(window).scroll(function(){
var top = jQuery(document).scrollTop();
var batas = jQuery(window).height();
//alert(batas);
if(top > batas) {
jQuery('.unfixed-menu').addClass('show-fixed-menu');
} else {
jQuery('.unfixed-menu').removeClass('show-fixed-menu');
}
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
</div>
<?php endif; ?>
HTML
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center">
<div class="modal-content">
<div class="modal-header">
// Usage:
$args = array(
'menu' => 'Menu Name',
'submenu' => 'About Us',
);
wp_nav_menu( $args );
//Paste this in function.php
@kirandash
kirandash / Gravity Forms + Bootstrap
Created July 14, 2016 10:00
Helpful function for adding Bootstrap classes to Gravity Forms fields.
<?php
/**
* Gravity Forms Bootstrap Styles
*
* Applies bootstrap classes to various common field types.
* Requires Bootstrap to be in use by the theme.
*
* Using this function allows use of Gravity Forms default CSS
* in conjuction with Bootstrap (benefit for fields types such as Address).
*
//Get page title with ID
$pageID = 26;
$page = get_post($pageID);
echo $page->post_title;
echo $page->post_content;
//Get page thumbnail with ID
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id('26'), 'post');
echo $thumb[0];