Skip to content

Instantly share code, notes, and snippets.

@mariojankovic
Created August 30, 2021 14:34
Show Gist options
  • Save mariojankovic/b27174f68bcb42558dfae4accf47316d to your computer and use it in GitHub Desktop.
Save mariojankovic/b27174f68bcb42558dfae4accf47316d to your computer and use it in GitHub Desktop.
VSCode HTML snippets
{
/*
// Place your snippets for HTML here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
*/
// HTML
"SVG icon": {
"prefix": "icon",
"body": [
"<svg aria-hidden=\"true\" class=\"icon-${1}\"><use xlink:href=\"#${1}\"></use></svg>"
]
},
// PHP: General
"PHP init": {
"prefix": "php",
"body": [
"<?php $1 ?>"
]
},
"PHP echo language": {
"prefix": "phpe",
"body": [
"<?php _e('${1}', '${2:theme}'); ?>"
]
},
// Wordpress: ACF
"ACF flexible field": {
"prefix": "flexible",
"body": [
"<?php if( have_rows('${1:flexibleField}') ): while ( have_rows('${1:flexibleField}') ) : the_row(); ?>",
"\t<?php if( get_row_layout() == '${2:flexibleSubField}' ): ?>",
"\t\t${3:<!-- Content -->}",
"\t<?php endif; ?>",
"<?php endwhile; ?>",
"<?php else : ?>",
"\t<!-- No layouts found -->",
"<?php endif; ?>"
]
},
"ACF repeater field": {
"prefix": "repeater",
"body": [
"<?php if ( have_rows('${1:flexibleField}') ): ?>",
"\t<?php while ( have_rows('${1:flexibleField}') ) : the_row(); ?>",
"\t${2:<!-- Content -->}",
"\t<?php endwhile; ?>",
"<?php endif; ?>"
]
},
"ACF field": {
"prefix": "field",
"body": [
"<?php the${2:_sub}_field('${1:field_name}'); ?>"
]
},
"ACF post object": {
"prefix": "post",
"body": [
"<?php $post_object = get_field('post_object');",
"\tif( $post_object ):",
"\t\t$post = $post_object;",
"\t\tsetup_postdata($post);",
"\t?>",
"\t<?php wp_reset_postdata(); ?>",
"<?php endif; ?>"
]
},
"ACF image object": {
"prefix": "image",
"body": [
"<?php $${2:image}_id = get${5:_sub}_field('${1:field_name}');",
"\t$${2:image}_size = '${3:thumb_hd}';",
"\t$${2:image} = wp_get_attachment_image_src( $${2:image}_id, $${2:image}_size );",
"?>",
"<?php echo $${2:image}[0]; ?>"
]
},
"WP query": {
"prefix": "query",
"body": [
"<?php $${1:wp_query} = new WP_Query(array(",
"\t'post_type' => '${2:post}',",
"\t'posts_per_page' => '${3:-1}'",
"));",
"if ($${1:wp_query}->have_posts()) : ?>",
"<?php while ($${1:wp_query}->have_posts()) : $${1:wp_query}->the_post(); ?>\n",
"<?php endwhile; ?>",
"<?php endif; ?>"
]
},
"WP define": {
"prefix": "define",
"body": [
"define('WP_HOME','${1:http://localhost/}${2:}');",
"define('WP_SITEURL','${1:http://localhost/}${2:}');"
]
},
"WP bloginfo": {
"prefix": "bloginfo",
"body": [
"<?php bloginfo('${1:template_directory}'); ?>"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment