WP NAV
WordPress
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'items_wrap' => '<ul>%3$s</ul>' ) ); ?>
Search Count
WordPress
<?php echo $wp_query->found_posts; ?> Search Result(s) For "<?php the_search_query(); ?>"
Template Part
WordPress
<?php get_template_part( 'partials/nav' ); ?>
WordPress Home URL
WordPress
<?php echo home_url(); ?>
Row Index
ACF
<div class="accordion" id="accordion-<?php echo get_row_index(); ?>">
Responsive Image
HTML
<picture>
<source media="(max-width: 799px)" srcset="smallimg.jpg">
<source media="(min-width: 800px)" srcset="bigimage.jpg">
<img src="bigimage.jpg" alt="">
</picture>
Font Options
CSS
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeSpeed;
-webkit-text-size-adjust: 100%;
font-feature-settings: "kern";
Vertical Align
CSS
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
iOS Specific
CSS
@supports (-webkit-touch-callout: none) {
body {
//code
}
}
jQuery $ Fix
JS
jQuery(document).ready(function( $ ) {
});
Copyright Date
PHP
© <?php echo date('Y'); ?>
ACF Select Conditional
ACF
<?php if( get_field('color') == 'red' ) {?>
// Do something.
<?php };?>
Button Shortcode
WordPress
/* button */
add_shortcode( 'custom-button', 'custom_button_shortcode' );
function custom_button_shortcode( $atts ) {
extract( shortcode_atts(
array(
'title' => 'title',
'url' => ''
),
$atts
));
return '<a target="' . $target . '" class="" href="' . $url . '">' . $title . '</a>';
}
[custom-button title="#" url="#"]
Lorem Ipsum
Placeholder
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc congue libero at feugiat aliquam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec finibus tortor nec orci commodo, at finibus lorem varius. Vivamus quis gravida mauris. Nam faucibus sit amet sapien at semper. Sed sodales erat vel suscipit finibus. Etiam nec rhoncus mi. Nam laoreet sed mi non imperdiet.</p>
ACF Image Size (Array)
ACF
<?php $image = get_sub_field('image'); ?>
<img src="<?php echo $image['sizes']['square']; ?>" />
ACF True/False
ACF
<?php if ( get_field( 'field_name' ) ): ?>
This is displayed when the field_name is TRUE or has a value.
<?php else: ?>
This is displayed when the field is FALSE, NULL or the field does not exist.
<?php endif; ?>
Do Shortcode
WordPress
<?php echo do_shortcode("[shortcode]"); ?>
CPT Loop
WordPress
<?php query_posts('post_type=POSTTYPE&posts_per_page=5'); if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; wp_reset_query(); ?>
Favicon Meta
HTML
<link rel="shortcut icon" href="<?php echo home_url(); ?>/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" sizes="57x57" href="<?php echo home_url(); ?>/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="<?php echo home_url(); ?>/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="<?php echo home_url(); ?>/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="<?php echo home_url(); ?>/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="<?php echo home_url(); ?>/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="<?php echo home_url(); ?>/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="<?php echo home_url(); ?>/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="<?php echo home_url(); ?>/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="<?php echo home_url(); ?>/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="<?php echo home_url(); ?>/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="<?php echo home_url(); ?>/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="<?php echo home_url(); ?>/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="<?php echo home_url(); ?>/android-chrome-192x192.png" sizes="192x192">
ACF Options
ACF
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Options',
'menu_title' => 'Theme Options',
'menu_slug' => 'theme-options',
'capability' => 'edit_posts',
'redirect' => false
));
}
CSS Grid
CSS
.grid {
width: 100%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-column-gap: 40px;
grid-row-gap: 40px;
justify-items: stretch;
align-items: inital;
}
ACF Relationship
ACF
<?php $posts = get_field('relationship_field_name'); if( $posts ): ?>
<ul>
<?php foreach( $posts as $post): setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); endif; ?>
Transition CSS
CSS
transition: all 0.3s ease-in;
transition: all 0.3s ease-in-out;
Featured Image URL
WordPress
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'IMGSIZE');
ACF Repeater (Basic)
ACF
<?php if( have_rows('repeater_field_name') ): while ( have_rows('repeater_field_name') ) : the_row();?>
<?php the_sub_field('sub_field_name');?>
<?php endwhile; else : endif; ?>
Trim Words
WordPress
echo wp_trim_words( get_the_content(), 100 ); // post content
echo wp_trim_words( get_the_excerpt(), 100 ); // post excerpt
echo wp_trim_words( get_the_title(), 100 ); // post title