Skip to content

Instantly share code, notes, and snippets.

@j-mccarthy
Last active May 10, 2017 18:31
Show Gist options
  • Save j-mccarthy/9785116 to your computer and use it in GitHub Desktop.
Save j-mccarthy/9785116 to your computer and use it in GitHub Desktop.
Useful Wordpress Snippets
<?php
// Get the_content by post id
echo apply_filters('the_content', get_post_field('post_content', $post_id));
// Featured Image display
$attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( $wp_postmeta->_wp_attachment_image_alt )),
);
if ( has_post_thumbnail() ) {
the_post_thumbnail( $size, $attr );
}
// wp_get_attachment_image with class
echo wp_get_attachment_image( get_sub_field( 'slider_image' ), 'medium', false, array( 'class' => 'attachment-medium featured' ) );
// conditional call sidebar
<?php if ( is_active_sidebar( 'primary' ) ) : ?>
<div id="sidebar-primary" class="sidebar">
<?php dynamic_sidebar( 'primary' ); ?>
</div>
<?php endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment