Skip to content

Instantly share code, notes, and snippets.

View mikeoberdick's full-sized avatar

Mike Oberdick mikeoberdick

View GitHub Profile
@mikeoberdick
mikeoberdick / plus_to_minus_css_animation.scss
Created June 2, 2021 17:01
Morph a plus icon into a minus icon for accordians and menus
/*
<div class = "plus-to-minus">
<span></span>
<span></span>
</div>
*/
.question-container {
.plus-to-minus {
width: 50px;
@mikeoberdick
mikeoberdick / parallax.css
Created June 1, 2021 14:52
Parallax effect for background images
<section id="sectionFour">
<?php $img = $four['full_size_image']; ?>
<div class="parallax" style = "background: url('<?php echo $img['url']; ?>');"></div>
</section><!-- #sectionFour -->
.parallax {
min-height: 500px;
background-attachment: fixed !important;
background-position: center !important;
background-repeat: no-repeat !important;
@mikeoberdick
mikeoberdick / sort_posts_by_most_popular.php
Last active May 16, 2021 12:20
Track post views and then sort by post views in order to display most read posts
@mikeoberdick
mikeoberdick / dropdown_by_post_type_in_ninja_forms.php
Created May 16, 2021 11:10
Create a drop down list that pulls a custom post type such as events in Ninja Forms
add_filter( 'ninja_forms_render_default_value', 'nf_hidden_field_values', 10, 3 );
// Populate event names for dropdown
add_filter( 'ninja_forms_render_options', function($options,$field_settings){
if( $field_settings['key'] == 'event_names' ) {
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$the_query = new WP_Query( $args );
@mikeoberdick
mikeoberdick / default_pagination.html
Created May 5, 2021 21:02
pagination for default query
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $qry->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'end_size' => 2,
'mid_size' => 1,
@mikeoberdick
mikeoberdick / custom_excerpt_for_acf_fields.php
Last active July 28, 2022 15:23
Create a custom excerpt from ACF field
//Custom excerpts for ACF fields
function wp_trim_excerpt_modified($text, $content_length = 55, $remove_breaks = false) {
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = excerpt_remove_blocks( $text );
$text = apply_filters( 'the_content', $text );
$text = str_replace(']]>', ']]&gt;', $text);
$num_words = $content_length;
$original_text = $text;
$text = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $text );
@mikeoberdick
mikeoberdick / shopify_run_iteration_on_loop.liquid
Created April 28, 2021 00:16
Use the following when adding iteration based content in shopify
{% for block in section.blocks %}
{% assign count = 1 %}
data-aos="{% if count == 1 or count == 3 %}fade-up-right{% else %}}fade-up-left{% endif %}"
{% assign count = count | plus: 1 %}
{% endfor %}
@mikeoberdick
mikeoberdick / set_all_elements_match_widest.js
Created April 14, 2021 00:51
function for setting a set of elements to match the widest in the set
$.fn.widest = function() {
return this.length ? this.width(Math.max.apply(Math, this.map(function() {
return $(this).width();
}))) : this;
};
@mikeoberdick
mikeoberdick / transparent_bg_drop_shadow.css
Last active April 29, 2021 00:40
Drop shadow CSS for png image with transparent background
-webkit-filter: drop-shadow(5px 5px 5px rgba(0,0,0,.75));
filter: drop-shadow(5px 5px 5px rgba(0,0,0,.75));
@mikeoberdick
mikeoberdick / pull_ninja_form_field_values_on_submit.js
Created February 1, 2021 16:54
Dynamically grab field values from Ninja Form fields on submit
<script>
var getQuoteFields = Marionette.Object.extend( {
initialize: function() {
this.listenTo( Backbone.Radio.channel( 'forms' ), 'submit:response', this.actionSubmit );
},
actionSubmit: function( response ) {
$sqFootage = response.data['fields'][15]['value'];
//Remove the hypens and replace with spaces
$county = response.data['fields'][10]['value'].replace(/-/g, " ");
jQuery('#squareFootage').text($sqFootage);