Advertisement
srikat

Genesis Snippets for Visual Studio Code

Dec 27th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.50 KB | None | 0 0
  1. {
  2. /*
  3. // Place your snippets for PHP here. Each snippet is defined under a snippet name and has a prefix, body and
  4. // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  5. // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
  6. // same ids are connected.
  7. // Example:
  8. "Print to console": {
  9. "prefix": "log",
  10. "body": [
  11. "console.log('$1');",
  12. "$2"
  13. ],
  14. "description": "Log output to console"
  15. }
  16. */
  17.  
  18. "Remove Header Right Widget Area": {
  19. "prefix": "remove_header_right_widget_area",
  20. "body": [
  21. "// Remove header right widget area.",
  22. "unregister_sidebar( 'header-right' );"
  23. ],
  24. "description": "Remove Header Right Widget Area"
  25. },
  26.  
  27. "Register Widget Area": {
  28. "prefix": "rwa",
  29. "body": [
  30. "// Register `${1:home-featured}` widget area.",
  31. "genesis_register_widget_area(",
  32. " array(",
  33. " 'id' => '${1:home-featured}',",
  34. " 'name' => __( '${2:Home Featured}', 'my-theme-text-domain' ),",
  35. " 'description' => __( 'This is the ${3:home featured} section.', 'my-theme-text-domain' ),",
  36. " )",
  37. ");"
  38. ],
  39. "description": "Register a widget area in Genesis."
  40. },
  41.  
  42. "Register Multiple Widget Areas": {
  43. "prefix": "register_multiple_Widget_areas",
  44. "body": [
  45. "// Register ${1:front-page} widget areas.",
  46. "for ( \\$i = 1; \\$i <= 4; \\$i++ ) {",
  47. " genesis_register_widget_area(",
  48. " array(",
  49. " 'id' => \"${1:front-page}-{\\$i}\",",
  50. " 'name' => __( \"${2:Front Page} {\\$i}\", 'my-theme-text-domain' ),",
  51. " 'description' => __( \"This is the ${3:front page} {\\$i} section.\", 'my-theme-text-domain' ),",
  52. " )",
  53. " );",
  54. "}"
  55. ],
  56. "description": "Register Multiple Widget Areas"
  57. },
  58.  
  59. "Display Widget Area": {
  60. "prefix": "dwa",
  61. "body": [
  62. "// Display `${1:home-featured}` widget area.",
  63. "genesis_widget_area( '${1:home-featured}', array(",
  64. " 'before' => '<div class=\"${1:home-featured} widget-area\"><div class=\"wrap\">',",
  65. " 'after' => '</div></div>',",
  66. ") );"
  67. ],
  68. "description": "Display a widget area in Genesis."
  69. },
  70.  
  71. "Register Custom Image Size": {
  72. "prefix": "register_custom_image_size",
  73. "body": [
  74. "// Register custom size for images on ${1:content archives}.",
  75. "add_image_size( '${2:content-archive-image}', ${3:800}, ${4:500}, true );"
  76. ],
  77. "description": "Register Custom Image Size"
  78. },
  79.  
  80. "Published Post Date": {
  81. "prefix": "date",
  82. "body": [
  83. "// date.",
  84. "echo do_shortcode( '[post_date]' );"
  85. ],
  86. "description": "Published Post Date in Genesis"
  87. },
  88.  
  89. "Display Featured Image": {
  90. "prefix": "image",
  91. "body": [
  92. "if ( has_post_thumbnail() ) {",
  93. " // get the URL of featured image.",
  94. " \\$image_url = genesis_get_image( 'format=url&size=large' );",
  95. "} else {",
  96. " // a placeholder.",
  97. " \\$image_url = 'http://lorempixel.com/1024/1024';",
  98. "}",
  99. "",
  100. "// get the alt text of featured image.",
  101. "\\$thumb_id = get_post_thumbnail_id( get_the_ID() );",
  102. "\\$alt = get_post_meta( \\$thumb_id, '_wp_attachment_image_alt', true );",
  103. "",
  104. "// if no alt text is present for featured image, set it to entry title.",
  105. "if ( '' === \\$alt ) {",
  106. " \\$alt = the_title_attribute( 'echo=0' );",
  107. "}",
  108. "",
  109. "// display the image.",
  110. "printf( '<figure class=\"story-image\"><img src=\"%s\" alt=\"%s\" /></figure>', \\$image_url, \\$alt );"
  111. ],
  112. "description": "Display Featured Image in Genesis"
  113. },
  114.  
  115. "URL of Featured Image": {
  116. "prefix": "image_url",
  117. "body": [
  118. "// get the URL of featured image.",
  119. "\\$image_url = genesis_get_image( 'format=url&size=large' );"
  120. ],
  121. "description": "URL of featured image in Genesis"
  122. },
  123.  
  124. "Entry Title": {
  125. "prefix": "title",
  126. "body": [
  127. "// title.",
  128. "genesis_do_post_title();"
  129. ],
  130. "description": "Entry Title in Genesis"
  131. },
  132.  
  133. "Remove Primary Nav": {
  134. "prefix": "remove_primary_nav",
  135. "body": [
  136. "// Remove the primary navigation menu.",
  137. "remove_action( 'genesis_after_header', 'genesis_do_nav' );"
  138. ],
  139. "description": "Remove Primary Nav in Genesis"
  140. },
  141.  
  142. "Add Categories and Tags Support to CPT": {
  143. "prefix": "add_categories_and_tags_support_to_cpt",
  144. "body": [
  145. "// Add Categories and Tags support to `${1:portfolio}` CPT.",
  146. "add_action( 'init', 'sk_add_category_tag_${1:portfolio}' );",
  147. "function sk_add_category_tag_${1:portfolio}() {",
  148. " register_taxonomy_for_object_type( 'category', '${1:portfolio}' );",
  149. " register_taxonomy_for_object_type( 'post_tag', '${1:portfolio}' );",
  150. "}"
  151. ],
  152. "description": "Add Categories and Tags support to CPT in WordPress"
  153. },
  154.  
  155. "Remove Footer Widgets": {
  156. "prefix": "remove_footer_widgets",
  157. "body": [
  158. "// Remove Footer Widgets.",
  159. "remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );"
  160. ],
  161. "description": "Remove Footer Widgets in Genesis"
  162. },
  163.  
  164. "Add Archive Settings Support for CPT": {
  165. "prefix": "add_archive_settings_support_for_cpt",
  166. "body": [
  167. "// Add Archive Settings option to `${1:portfolio}` CPT.",
  168. "add_post_type_support( '${1:portfolio}', 'genesis-cpt-archives-settings' );"
  169. ],
  170. "description": "Add Archive Settings support for CPT in Genesis"
  171. },
  172.  
  173. "Full Width Page Template": {
  174. "prefix": "full_width_page_template",
  175. "body": [
  176. "<?php",
  177. "",
  178. "add_filter( 'genesis_attr_site-inner', 'be_site_inner_attr' );",
  179. "/**",
  180. " * Add the attributes from 'entry', since this replaces the main entry.",
  181. " *",
  182. " * @author Bill Erickson",
  183. " * @link http://www.billerickson.net/full-width-landing-pages-in-genesis/",
  184. " *",
  185. " * @param array \\$attributes Existing attributes.",
  186. " * @return array Amended attributes.",
  187. " */",
  188. "function be_site_inner_attr( \\$attributes ) {",
  189. " // Add a class of 'full' for styling this .site-inner differently.",
  190. " \\$attributes['class'] .= ' full';",
  191. "",
  192. " // Add an id of 'genesis-content' for accessible skip links.",
  193. " \\$attributes['id'] = 'genesis-content';",
  194. "",
  195. " // Add the attributes from .entry, since this replaces the main entry.",
  196. " \\$attributes = wp_parse_args( \\$attributes, genesis_attributes_entry( array() ) );",
  197. "",
  198. " return \\$attributes;",
  199. "}",
  200. "",
  201. "// Display header.",
  202. "get_header();",
  203. "",
  204. "// Content.",
  205. "echo 'Hello World';",
  206. "",
  207. "// Display Footer.",
  208. "get_footer();",
  209. "",
  210. "/* Front Page Template for Full Width Sections",
  211. "-------------------------------------------- */",
  212. "",
  213. "/*.site-inner.full {",
  214. " max-width: none;",
  215. " padding-top: 0;",
  216. "}*/"
  217. ],
  218. "description": "Full Width Page Template in Genesis"
  219. },
  220.  
  221. "Structural Wraps": {
  222. "prefix": "structural_wraps",
  223. "body": [
  224. "// Remove `$1` from structural wrap.",
  225. "add_theme_support( 'genesis-structural-wraps', array( 'header', 'menu-primary', 'menu-secondary', 'footer-widgets', 'footer' ) );"
  226. ],
  227. "description": "Structural Wraps in Genesis"
  228. },
  229.  
  230. "Search Form Input Text": {
  231. "prefix": "search_form_input_text",
  232. "body": [
  233. "add_filter( 'genesis_search_text', 'custom_search_text' );",
  234. "/**",
  235. " * Customize search form input box text.",
  236. " *",
  237. " * @param string \\$text Default search input text.",
  238. " * @return Modified search input text.",
  239. " */",
  240. "function custom_search_text( \\$text ) {",
  241. " return esc_attr( '${1:Search my blog...}' );",
  242. "}"
  243. ],
  244. "description": "Search Form Input Text"
  245. },
  246.  
  247. "Customize Links to Previous and Next Entries on Singular Entries": {
  248. "prefix": "customize_links_to_previous_and_next_entries_on_singular_entries",
  249. "body": [
  250. "add_action( 'genesis_after_entry', 'custom_adjacent_entry_nav' );",
  251. "/**",
  252. " * Display links to previous and next entry.",
  253. " *",
  254. " * @since 2.3.0",
  255. " *",
  256. " * @return void Return early if not singular or post type doesn't support `genesis-adjacent-entry-nav`.",
  257. " */",
  258. "function custom_adjacent_entry_nav() {",
  259. "",
  260. " if ( ! is_singular() ) {",
  261. " return;",
  262. " }",
  263. "",
  264. " genesis_markup( array(",
  265. " 'open' => '<div %s>',",
  266. " 'context' => 'adjacent-entry-pagination',",
  267. " ) );",
  268. "",
  269. " echo '<div class=\"pagination-previous alignleft\">';",
  270. " previous_post_link( '%link', '< Previous' );",
  271. " echo '</div>';",
  272. "",
  273. " echo '<div class=\"pagination-next alignright\">';",
  274. " next_post_link( '%link', 'Next >' );",
  275. " echo '</div>';",
  276. "",
  277. " genesis_markup( array(",
  278. " 'close' => '</div>',",
  279. " 'context' => 'adjacent-entry-pagination',",
  280. " ) );",
  281. "",
  282. "}"
  283. ],
  284. "description": "Customize Links to Previous and Next Entries on Singular Entries"
  285. },
  286.  
  287. "Unregister Primary Sidebar": {
  288. "prefix": "unregister_primary_sidebar",
  289. "body": [
  290. "// Unregister primary sidebar.",
  291. "unregister_sidebar( 'sidebar' );"
  292. ],
  293. "description": "Unregister Primary Sidebar"
  294. },
  295.  
  296. "Unregister Secondary Sidebar": {
  297. "prefix": "unregister_secondary_sidebar",
  298. "body": [
  299. "// Unregister secondary sidebar.",
  300. "unregister_sidebar( 'sidebar-alt' );"
  301. ],
  302. "description": "Unregister Secondary Sidebar"
  303. },
  304.  
  305. "Add Post Navigation for Single Posts": {
  306. "prefix": "add_post_navigation_for_single_posts",
  307. "body": [
  308. "// Add post navigation.",
  309. "add_action( 'genesis_after_loop', 'genesis_prev_next_post_nav' );"
  310. ],
  311. "description": "Add Post Navigation for Single Posts"
  312. },
  313.  
  314. "Customize Previous Page and Next Page text in Content Archives Post Navigation": {
  315. "prefix": "customize_previous_page_and_next_page_text_in_content_archives_post_navigation",
  316. "body": [
  317. "add_filter ( 'genesis_prev_link_text' , 'sp_previous_page_link' );",
  318. "/**",
  319. " * Customize the previous page link.",
  320. " *",
  321. " * @param string \\$text Default text for previous page link, \"Previous Page\".",
  322. " * @return Modified previous page link text.",
  323. " */",
  324. "function sp_previous_page_link ( \\$text ) {",
  325. " return g_ent( '&laquo; ' ) . __( '${1:Previous Page}', CHILD_DOMAIN );",
  326. "}",
  327. "",
  328. "add_filter ( 'genesis_next_link_text' , 'sp_next_page_link' );",
  329. "/**",
  330. " * Customize the next page link.",
  331. " *",
  332. " * @param string \\$text Default text for next page link, \"Next Page\".",
  333. " * @return Modified next page link text.",
  334. " */",
  335. "function sp_next_page_link ( \\$text ) {",
  336. " return __( '${2:Next Page}', CHILD_DOMAIN ) . g_ent( ' &raquo; ' );",
  337. "}"
  338. ],
  339. "description": "Customize Previous Page and Next Page text in Content Archives Post Navigation"
  340. },
  341.  
  342. "Split Entries into Columns": {
  343. "prefix": "columns",
  344. "body": [
  345. "add_filter( 'post_class', 'custom_portfolio_post_class' );",
  346. "/**",
  347. " * Display as Columns.",
  348. " *",
  349. " * @param string \\$classes Existing post classes.",
  350. " * @return Modified post classes.",
  351. " */",
  352. "function custom_portfolio_post_class( \\$classes ) {",
  353. " if ( is_main_query() ) { // conditional to ensure that column classes do not apply to Featured widgets",
  354. " \\$columns = ${1:3}; // Set the number of columns here",
  355. "",
  356. " \\$column_classes = array( '', '', 'one-half', 'one-third', 'one-fourth', 'one-fifth', 'one-sixth' );",
  357. "",
  358. " \\$classes[] = \\$column_classes[ \\$columns ];",
  359. "",
  360. " global \\$wp_query;",
  361. "",
  362. " if ( 0 == \\$wp_query->current_post || 0 == \\$wp_query->current_post % \\$columns ) {",
  363. " \\$classes[] = 'first';",
  364. " }",
  365. " }",
  366. "",
  367. " return \\$classes;",
  368. "}"
  369. ],
  370. "description": "Split Entries into Columns"
  371. },
  372.  
  373. "Remove Archive Pagination": {
  374. "prefix": "remove_archive_pagination",
  375. "body": [
  376. "// Remove Archive Pagination.",
  377. "remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );"
  378. ],
  379. "description": "Remove Archive Pagination in Genesis"
  380. }
  381.  
  382. "Remove entry header": {
  383. "prefix": "remove_entry_header",
  384. "body": [
  385. "// Remove entry header.",
  386. "remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );",
  387. "remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );",
  388. "remove_action( 'genesis_entry_header', 'genesis_do_post_title' );",
  389. "remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );"
  390. ],
  391. "description": "Remove Entry Header in Genesis"
  392. },
  393.  
  394. "Remove post info": {
  395. "prefix": "remove_post_info",
  396. "body": [
  397. "// Remove post info.",
  398. "remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );"
  399. ],
  400. "description": "Remove Post Info in Genesis"
  401. },
  402.  
  403. "Remove entry image": {
  404. "prefix": "remove_entry_image",
  405. "body": [
  406. "// Remove entry image (from theme settings).",
  407. "remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );"
  408. ],
  409. "description": "Remove entry image in Genesis"
  410. },
  411.  
  412. "Remove Entry Footer": {
  413. "prefix": "remove_entry_footer",
  414. "body": [
  415. "// Remove entry footer.",
  416. "remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );",
  417. "remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );",
  418. "remove_action( 'genesis_entry_footer', 'genesis_post_meta' );"
  419. ],
  420. "description": "Remove Entry Footer in Genesis"
  421. },
  422.  
  423. "Remove Entry Meta": {
  424. "prefix": "remove_entry_meta",
  425. "body": [
  426. "// Remove entry meta.",
  427. "remove_action( 'genesis_entry_footer', 'genesis_post_meta' );"
  428. ],
  429. "description": "Remove Entry Meta in Genesis"
  430. },
  431.  
  432. "Modify Read More Link when using the Content Limit": {
  433. "prefix": "modify_read_more_link_when_using_the_content_limit",
  434. "body": [
  435. "add_filter( 'get_the_content_more_link', 'sp_read_more_link' );",
  436. "/**",
  437. " * Modify the Genesis content limit read more link.",
  438. " *",
  439. " * @return Modified read more link for the content limit.",
  440. " */",
  441. "function sp_read_more_link() {",
  442. " return '... <a class=\"more-link\" href=\"' . get_permalink() . '\">${1:[Continue Reading]}</a>';",
  443. "}"
  444. ],
  445. "description": "Modify Read More Link when using the Content Limit"
  446. }
  447.  
  448. "Reposition Footer Widgets": {
  449. "prefix": "reposition_footer_widgets",
  450. "body": [
  451. "// Reposition footer widgets.",
  452. "remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );",
  453. "add_action( 'genesis_after', 'genesis_footer_widget_areas' );"
  454. ],
  455. "description": "Reposition Footer Widgets"
  456. },
  457.  
  458. "Reposition Footer": {
  459. "prefix": "reposition_footer",
  460. "body": [
  461. "// Reposition footer.",
  462. "remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );",
  463. "remove_action( 'genesis_footer', 'genesis_do_footer' );",
  464. "remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );",
  465. "add_action( 'genesis_after', 'genesis_footer_markup_open', 11 );",
  466. "add_action( 'genesis_after', 'genesis_do_footer', 12 );",
  467. "add_action( 'genesis_after', 'genesis_footer_markup_close', 13 );"
  468. ],
  469. "description": "Reposition Footer"
  470. },
  471.  
  472. "Template Redirect": {
  473. "prefix": "template_redirect",
  474. "body": [
  475. "add_filter( 'template_include', 'custom_template_redirect' );",
  476. "/**",
  477. " * Use ${1:archive-portfolio}.php for ${2:portfolio category and tag taxonomy archives}.",
  478. " *",
  479. " * @param string \\$template The path of the template to include.",
  480. " * @return The filtered path of the template to include.",
  481. " */",
  482. "function custom_template_redirect( \\$template ) {",
  483. " if ( ${3:is_tax( 'portfolio_category' ) || is_tax( 'portfolio_tag' )} ) {",
  484. " \\$template = get_query_template( '${1:archive-portfolio}' );",
  485. " }",
  486. "",
  487. " return \\$template;",
  488. "}"
  489. ],
  490. "description": "Template Redirect in WordPress"
  491. },
  492.  
  493. "Customize the WordPress Query": {
  494. "prefix": "pre_get_posts",
  495. "body": [
  496. "add_action( 'pre_get_posts', '${1:be_exclude_category_from_blog}' );",
  497. "/**",
  498. " * ${2:Exclude Category from Blog}.",
  499. " *",
  500. " * @author Bill Erickson",
  501. " * @link http://www.billerickson.net/customize-the-wordpress-query/",
  502. " * @param object \\$query data.",
  503. " */",
  504. "function ${1:be_exclude_category_from_blog}( \\$query ) {",
  505. " if ( \\$query->is_main_query() && ${3:\\$query->is_home()} ) {",
  506. " \\$query->${4:set( 'cat', '-4' )};",
  507. " }",
  508. "}"
  509. ],
  510. "description": "Customize the WordPress Query"
  511. },
  512.  
  513. "Enqueue Font Awesome": {
  514. "prefix": "font_awesome",
  515. "body": [
  516. "wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' );",
  517. ],
  518. "description": "Enqueue Font Awesome"
  519. }
  520. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement