Skip to content

Instantly share code, notes, and snippets.

@deardorffdev
Forked from j-mccarthy/wp-snippets.php
Created May 10, 2017 18:31
Show Gist options
  • Save deardorffdev/887b731a6b384706d882c64763f2d0c1 to your computer and use it in GitHub Desktop.
Save deardorffdev/887b731a6b384706d882c64763f2d0c1 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