Skip to content

Instantly share code, notes, and snippets.

View mikeott's full-sized avatar
😀
Greetings programs. See you on the grid.

Michael Ott mikeott

😀
Greetings programs. See you on the grid.
View GitHub Profile
@mikeott
mikeott / load-posts-with-ajax-on-click.md
Last active May 26, 2023 07:22
Load posts using AJAX on click

Load posts onclick with AJAX.

Add to page template

<div id="post-container">
 /* Post titles will be inserted here */
</div>

<button id="load-more">Load More</button>
@mikeott
mikeott / php-version-compare.php
Created March 19, 2023 09:43
PHP version compare
if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
echo 'I am using PHP 5, my version: ' . PHP_VERSION . "\n";
@mikeott
mikeott / js-do-something-when-element-is-in-viewport.js
Last active February 22, 2023 03:11
JS do something when element is in viewport
$(window).scroll(function() {
var top_of_element = $("#my_element").offset().top;
var bottom_of_element = $("#my_element").offset().top + $("#my_element").outerHeight();
var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
var top_of_screen = $(window).scrollTop();
if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
// element is in view, do something
} else {
// element is out of view, do something else
@mikeott
mikeott / wordpress-shortcode-for-template-and-editor-usage.php
Created February 20, 2023 05:14
WordPress shortcode for template and editor usage
<?php /*
Board of Directors.
Template usage: <?php echo do_shortcode('[board_of_directors]'); ?>
Editor usage: Add a shortcode: [board_of_directors]
*/
function board_of_directors_code() {
if( have_rows('directors', 19) ) {
while( have_rows('directors', 19) ) : the_row();
@mikeott
mikeott / compare-versions.php
Last active January 19, 2023 01:36
PHP version compare
<?php
$current_version = '1.4.0';
$required_version = '3.9.2';
if (version_compare($current_version, $required_version) < 0) {
// Do something
}
?>
@mikeott
mikeott / if-checkbox-is-ticked.js
Created January 5, 2023 04:05
If checkbox is ticked
if( $('.finished-auctions').is(':checked') ) {
// Do something
}
@mikeott
mikeott / add-body-class-to-admin.php
Created November 30, 2022 00:52
Add body class to admin
/* Add body class to admin */
add_filter( 'admin_body_class', 'my_body_class' );
function my_body_class( $class ) {
$class .= ' stormbox-plugin ';
return $class;
}
@mikeott
mikeott / shortcode-with-attributes.php
Created November 24, 2022 07:51
Shortcode with attributes
<?php /*
Shortcode CTA button for use in the editor.
Example usage:
[button href="https://www.google.com.au" target="_blank"]Visit Google[/button]
*/
function button( $atts, $content = null ) {
$a = shortcode_atts( array(
'class' => 'button-link external',
'href' => '#',
@mikeott
mikeott / force-16-9-css-attribute.js
Last active November 11, 2022 06:02
Force 16 x 9 CSS attribute
$( document ).ready(function() {
var width = $('iframe').width();
$('iframe').css({
'width': width,
'height': width*(9/16)
});
});
@mikeott
mikeott / additional-user-profile-fields
Created September 24, 2022 23:03
WordPress additional user profile fields
/* Additional user profile fields */
function extra_profile_details( $methods ) {
$methods['new_email'] = __( "New email", "wproject" );
return $methods;
}
add_filter('user_contactmethods','extra_profile_details',10,1);