Skip to content

Instantly share code, notes, and snippets.

@AndrewGehman
AndrewGehman / gist:5b1790af626202a2ee43240f0fb8b890
Created June 21, 2022 01:04
Check if current WordPress page is parent
<?php>
// Check if current WP page is parent
$isParent = get_pages(array(
'child_of' => get_the_ID()
));
?>
@AndrewGehman
AndrewGehman / gist:a4c01007c2a85ac0b008d6f229eb7f25
Created March 8, 2020 22:02
JS - Smooth Scrolling to in page links
// scroll to in page linked sections
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
//ACF image using image ID and ACF field for image alt attribute
$img = wp_get_attachment_image_src(get_field('image'), 'img-size');
$img_alt = esc_attr(get_field('image_alt'));
$imgsrc = $img[0];
$imgwidth = $img[1];
$imgheight = $img[2];
$sizes_value = wp_get_attachment_image_sizes( get_field('image'), 'img-size' );
$sizes = $sizes_value ? ' sizes="' . esc_attr( $sizes_value ) . '"' : '';
@AndrewGehman
AndrewGehman / wp-remove-content-editor.php
Created April 11, 2019 18:25
Remove the WordPress Content Editor from Pages or Posts
// Remove the content editor from Wordpress
add_action( 'init', 'my_custom_init' );
function my_custom_init() {
// removes the content editor for Pages
remove_post_type_support( 'page', 'editor' );
// removes the content editor ofr all Posts
remove_post_type_support( 'post', 'editor' );
}
@AndrewGehman
AndrewGehman / wp-add-text-before-permalink.php
Created April 11, 2019 15:04
Add Text Description before the WordPress admin permalink
@AndrewGehman
AndrewGehman / wp-change-placeholder-title-text.php
Created April 11, 2019 15:02
Change the placeholder text of the WordPress Title
function ChangeTheTitlePlaceholder(){
return 'Put Your Awesome Title Here!';
}
add_filter( 'enter_title_here', 'ChangeTheTitlePlaceholder' );
@AndrewGehman
AndrewGehman / wp-featured-image-meta-box-text.php
Created April 11, 2019 14:59
Add Text to the Featured Image Meta Box in WordPress