Themes Development Quick Help

Lot of Source

Childthemes Style

  1. /*
  2. Theme Name: Twenty Twelve Child
  3. Theme URI: http://example.com/ /* optional */
  4. Description: Child theme for the Twenty Twelve theme /* optional */
  5. Author: Your name here /* optional */
  6. Author URI: http://example.com/about/ /* optional */
  7. Template: twentytwelve
  8. Version: 0.1.0 /* optional */
  9. */
  10. @import url("../themes-names/style.css");

Style CSS

  1. /**
  2. * Theme Name: Super Mario
  3. * Theme URI: http://devpress.com
  4. * Description: An example theme description.
  5. * Author: Your Name
  6. * Author URI: http://devpress.com
  7. * Version: 0.1
  8. * Tags: threaded-comments, translation-ready, two-columns, fixed-width
  9. * License: GNU General Public License v2.0
  10. * License URI: http://www.gnu.org/licenses/gpl-2.0.html
  11. */

Reset CSS

  1. /**
  2. * CSS RESET WITH CLEARFIX
  3. * http://meyerweb.com/eric/tools/css/reset/
  4. * v2.0 | 20110126
  5. * License: none (public domain)
  6. * -----------------------------------------------
  7. */
  8. html, body, div, span, applet, object, iframe,
  9. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  10. a, abbr, acronym, address, big, cite, code,
  11. del, dfn, em, img, ins, kbd, q, s, samp,
  12. small, strike, strong, sub, sup, tt, var,
  13. b, u, i, center,
  14. dl, dt, dd, ol, ul, li,
  15. fieldset, form, label, legend,
  16. table, caption, tbody, tfoot, thead, tr, th, td,
  17. article, aside, canvas, details, embed,
  18. figure, figcaption, footer, header, hgroup,
  19. menu, nav, output, ruby, section, summary,
  20. time, mark, audio, video {
  21.     margin: 0;
  22.     outline:none;
  23.     padding: 0;
  24.     border: 0;
  25.     font-size: 100%;
  26.     font: inherit;
  27.     vertical-align: baseline;
  28. }
  29. /* HTML5 display-role reset for older browsers */
  30. article, aside, details, figcaption, figure,
  31. footer, header, hgroup, menu, nav, section {
  32.     display: block;
  33. }
  34. blockquote, q {
  35.     quotes: none;
  36. }
  37. blockquote:before, blockquote:after,
  38. q:before, q:after {
  39.     content: '';
  40.     content: none;
  41. }
  42. table {
  43.     border-collapse: collapse;
  44.     border-spacing: 0;
  45. }
  46. .clear    { clear: both; display: block; height: 0; overflow: hidden; visibility: hidden; width: 0; }
  47. .clearfix:after {
  48.     content: ".";
  49.     display: block;
  50.     clear: both;
  51.     visibility: hidden;
  52.     line-height: 0;
  53.     height: 0;
  54. }
  55. .clearfix { display: inline-block;}
  56. html[xmlns] .clearfix { display: block; }
  57. * html .clearfix { height: 1%; }

Radius CSS

  • -webkit-border-radius: 10px;
  • -moz-border-radius: 10px;
  • border-radius: 10px;
  • -o-border-radius: 10px;
  • -icab-border-radius: 10px;
  • -khtml-border-radius: 10px;

Full Screen Background CSS

  1. min-height: 100%;
  2. min-width: 1024px;
  3. width: 100%;
  4. height: 100%;
  5. position: fixed;
  6. top: 0;
  7. left: 0;
  8. -webkit-background-size: cover;
  9. -moz-background-size: cover;
  10. -o-background-size: cover;
  11. background-size: cover;

Advance CPT n Meta Query

  1. function register_books_cpt() {
  2. $cpt_args = array(
  3. 'label' => 'Books',
  4. 'public' => true,
  5. 'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
  6. 'menu_icon' => 'dashicons-book',
  7. 'has_archive' => true,
  8. 'rewrite' => array('slug' => 'books'),
  9. );
  10. register_post_type('books', $cpt_args);
  11. $tax_args = array(
  12. 'label' => 'Genres',
  13. 'public' => true,
  14. 'hierarchical' => true, // Acts like categories (true) or tags (false)
  15. 'rewrite' => array('slug' => 'genres'),
  16. );
  17. register_taxonomy('genres', 'books', $tax_args);
  18. }
  19. add_action('init', 'register_books_cpt_taxonomy');
  20. $args = array(
  21. 'post_type' => 'books',
  22. 'tax_query' => array(
  23. 'relation' => 'AND', // Combine conditions
  24. array(
  25. 'taxonomy' => 'genres',
  26. 'field' => 'slug', // Can also use 'term_id'
  27. 'terms' => 'fiction', // Slug of the term
  28. ),
  29. array(
  30. 'taxonomy' => 'authors',
  31. 'field' => 'slug',
  32. 'terms' => 'j-k-rowling',
  33. ),
  34. ),
  35. );
  36. $args = array(
  37. 'post_type' => 'books',
  38. 'meta_query' => array(
  39. array(
  40. 'key' => 'publication_year',
  41. 'value' => '2020',
  42. 'compare' => '>=',
  43. 'type' => 'NUMERIC',
  44. ),
  45. ),
  46. );
  47. $args = array(
  48. 'post_type' => 'books',
  49. 'tax_query' => array(
  50. 'relation' => 'AND',
  51. array(
  52. 'taxonomy' => 'genres',
  53. 'field' => 'slug',
  54. 'terms' => 'fiction',
  55. ),
  56. array(
  57. 'taxonomy' => 'authors',
  58. 'field' => 'slug',
  59. 'terms' => 'j-k-rowling',
  60. ),
  61. ),
  62. 'meta_query' => array(
  63. array(
  64. 'key' => 'rating',
  65. 'value' => '4.5',
  66. 'compare' => '>=',
  67. 'type' => 'NUMERIC',
  68. ),
  69. ),
  70. );
  71. $args = array(
  72. 'post_type' => 'books',
  73. 'tax_query' => array(
  74. array(
  75. 'taxonomy' => 'genres',
  76. 'field' => 'slug',
  77. 'terms' => 'fantasy',
  78. 'include_children' => false,
  79. ),
  80. ),
  81. );
  82. tax_query Relations
  83. 'tax_query' => array(
  84. 'relation' => 'AND',
  85. array(
  86. 'taxonomy' => 'genres',
  87. 'field' => 'slug',
  88. 'terms' => 'fiction',
  89. ),
  90. array(
  91. 'taxonomy' => 'genres',
  92. 'field' => 'slug',
  93. 'terms' => 'fantasy',
  94. ),
  95. );
  96. 'tax_query' => array(
  97. 'relation' => 'OR',
  98. array(
  99. 'taxonomy' => 'genres',
  100. 'field' => 'slug',
  101. 'terms' => 'fiction',
  102. ),
  103. array(
  104. 'taxonomy' => 'genres',
  105. 'field' => 'slug',
  106. 'terms' => 'fantasy',
  107. ),
  108. );
  109. Nested Relations:
  110. 'tax_query' => array(
  111. 'relation' => 'OR',
  112. array(
  113. 'taxonomy' => 'genres',
  114. 'field' => 'slug',
  115. 'terms' => 'fiction',
  116. ),
  117. array(
  118. 'relation' => 'AND',
  119. array(
  120. 'taxonomy' => 'genres',
  121. 'field' => 'slug',
  122. 'terms' => 'fantasy',
  123. ),
  124. array(
  125. 'taxonomy' => 'genres',
  126. 'field' => 'slug',
  127. 'terms' => 'adventure',
  128. ),
  129. ),
  130. );
  131. meta_query Parameters
  132. Equality Comparison:
  133. = (Default): Equal to.
  134. !=: Not equal to.
  135. Example: Fetch books with a rating of exactly 4.5.
  136. php
  137. Copy code
  138. 'meta_query' => array(
  139. array(
  140. 'key' => 'rating',
  141. 'value' => '4.5',
  142. 'compare' => '=',
  143. ),
  144. );
  145. Range Comparison:
  146. >: Greater than.
  147. >=: Greater than or equal to.
  148. <: Less than.
  149. <=: Less than or equal to.
  150. Example: Fetch books with a rating of 4.5 or higher.
  151. php
  152. Copy code
  153. 'meta_query' => array(
  154. array(
  155. 'key' => 'rating',
  156. 'value' => '4.5',
  157. 'compare' => '>=',
  158. ),
  159. );
  160. Pattern Matching:
  161. LIKE: Value contains the given string.
  162. NOT LIKE: Value does not contain the string.
  163. Example: Fetch books where the description includes "bestseller".
  164. 'meta_query' => array(
  165. array(
  166. 'key' => 'description',
  167. 'value' => 'bestseller',
  168. 'compare' => 'LIKE',
  169. ),
  170. );
  171. List Comparison:
  172. IN: Value is in a list.
  173. NOT IN: Value is not in a list.
  174. Example: Fetch books with ratings of 4, 4.5, or 5.
  175. 'meta_query' => array(
  176. array(
  177. 'key' => 'rating',
  178. 'value' => array('4', '4.5', '5'),
  179. 'compare' => 'IN',
  180. ),
  181. );
  182. Null/Existence Check:
  183. EXISTS: Field exists.
  184. NOT EXISTS: Field does not exist.
  185. Example: Fetch books that have a custom field rating.
  186. 'meta_query' => array(
  187. array(
  188. 'key' => 'rating',
  189. 'compare' => 'EXISTS',
  190. ),
  191. );
  192. type Options
  193. Defines the data type for comparison. Available options are:
  194. NUMERIC:
  195. For numeric values.
  196. Example: Fetch books with a rating of 4.5 or higher.
  197. 'meta_query' => array(
  198. array(
  199. 'key' => 'rating',
  200. 'value' => '4.5',
  201. 'compare' => '>=',
  202. 'type' => 'NUMERIC',
  203. ),
  204. );
  205. CHAR (Default):
  206. For character-based data.
  207. Example: Fetch books with ISBN containing "978".
  208. 'meta_query' => array(
  209. array(
  210. 'key' => 'isbn',
  211. 'value' => '978',
  212. 'compare' => 'LIKE',
  213. 'type' => 'CHAR',
  214. ),
  215. );
  216. DATE:
  217. For date values.
  218. Example: Fetch books published after 2020-01-01.
  219. 'meta_query' => array(
  220. array(
  221. 'key' => 'publication_date',
  222. 'value' => '2020-01-01',
  223. 'compare' => '>',
  224. 'type' => 'DATE',
  225. ),
  226. );
  227. DATETIME:
  228. For datetime values.
  229. Example: Fetch books added to the database after 2023-01-01 12:00:00.
  230. 'meta_query' => array(
  231. array(
  232. 'key' => 'added_date',
  233. 'value' => '2023-01-01 12:00:00',
  234. 'compare' => '>',
  235. 'type' => 'DATETIME',
  236. ),
  237. );
  238. Combining Multiple meta_query Clauses
  239. You can use multiple meta queries with relation.
  240. Example: Fetch books with a rating of 4.5 or higher AND published after 2020.
  241. 'meta_query' => array(
  242. 'relation' => 'AND',
  243. array(
  244. 'key' => 'rating',
  245. 'value' => '4.5',
  246. 'compare' => '>=',
  247. 'type' => 'NUMERIC',
  248. ),
  249. array(
  250. 'key' => 'publication_date',
  251. 'value' => '2020-01-01',
  252. 'compare' => '>',
  253. 'type' => 'DATE',
  254. ),
  255. ),

Create Custom Sidebar

  1. function the_widgets_init() {
  2. if ( !function_exists('register_sidebars') )
  3. return;
  4. register_sidebar(array(
  5. 'name' => __('Sidebar'),
  6. 'id' => 'sidebar',
  7. 'description' => __('Appears on Sidebar'),
  8. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  9. 'after_widget' => '</div>',
  10. 'before_title' => '<h3>',
  11. 'after_title' => '</h3>'));
  12. }
  13. add_action( 'init', 'the_widgets_init' );
  14. // To Show
  15. <?php dynamic_sidebar( 'Sidebar' ); ?>

Normal Sidebar Register

  1. function the_widgets_init() {
  2. if ( !function_exists('register_sidebars') )
  3. return;
  4. register_sidebar(array('name' => 'Sidebar','id' => 'sidebar-1','before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'));
  5. }
  6. add_action( 'init', 'the_widgets_init' );

Custom Post Type

  • // Creates Custom post type
  • register_post_type('custom', array(
  • 'label' => 'Custom Post',
  • 'public' => true,
  • 'show_ui' => true,
  • 'capability_type' => 'post',
  • 'hierarchical' => false,
  • 'rewrite' => array('slug' => 'custom'),
  • 'query_var' => true,
  • 'supports' => array(
  • 'title',
  • 'editor',
  • 'excerpt',
  • 'trackbacks',
  • 'custom-fields',
  • 'comments',
  • 'revisions',
  • 'thumbnail',
  • 'author',
  • 'page-attributes',)
  • ) );
  • // To Show
  • <?php query_posts( 'post_type=custom'); ?>
  • <?php if (have_posts()) : ?>
  • <?php while (have_posts()) : the_post(); ?>
  • <?php the_title(); ?>
  • <?php the_content(''); ?>
  • <?php endwhile; ?>
  • <?php else : ?>
  • <!-- You can add Error Text here -->
  • <?php endif; ?>

Advance Custom Post Type

  1. add_action( 'init', 'register_custom_posts' );
  2. function register_custom_posts() {
  3. $labels = array(
  4. 'name' => _x( 'Custom Posts', 'custom_posts' ),
  5. 'singular_name' => _x( 'Custom Posts', 'custom_posts' ),
  6. 'add_new' => _x( 'Add New', 'custom_posts' ),
  7. 'add_new_item' => _x( 'Add New Custom Posts', 'custom_posts' ),
  8. 'edit_item' => _x( 'Edit Custom Posts', 'custom_posts' ),
  9. 'new_item' => _x( 'New Custom Posts', 'custom_posts' ),
  10. 'view_item' => _x( 'View Custom Posts', 'custom_posts' ),
  11. 'search_items' => _x( 'Search Custom Posts', 'custom_posts' ),
  12. 'not_found' => _x( 'No custom posts found', 'custom_posts' ),
  13. 'not_found_in_trash' => _x( 'No custom posts found in Trash', 'custom_posts' ),
  14. 'parent_item_colon' => _x( 'Parent Custom Posts:', 'custom_posts' ),
  15. 'menu_name' => _x( 'Custom Posts', 'custom_posts' ),
  16. );
  17. $args = array(
  18. 'labels' => $labels,
  19. 'hierarchical' => false,
  20. 'description' => 'Here you will add custom post',
  21. 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
  22. 'taxonomies' => array( 'category', 'post_tag', 'page-category', 'custom-taxonomies' ),
  23. 'public' => true,
  24. 'show_ui' => true,
  25. 'show_in_menu' => true,
  26. 'menu_position' => 5,
  27. 'menu_icon' => '',
  28. 'show_in_nav_menus' => true,
  29. 'publicly_queryable' => true,
  30. 'exclude_from_search' => false,
  31. 'has_archive' => true,
  32. 'query_var' => true,
  33. 'can_export' => true,
  34. 'rewrite' => true,
  35. 'capability_type' => 'post'
  36. );
  37. register_post_type( 'custom_posts', $args );
  38. }

Post Loop

  1. <?php while (have_posts()) : the_post(); ?>
  2. // DO SOMETHING WITH EACH POST THAT WE FOUND
  3. <?php endwhile; else: ?>
  4. // DO SOMETHING IF NOTHING WAS FOUND
  5. <?php endif; ?>

Advance Post Query

  1. নির্দিষ্ট বিভাগের পোষ্ট দেখাতে চাইলে
  2. <?php query_posts('category_name=blog'); ?>
  3. বি:দ্র: এখানে blog হল বিভাগের url slug
  4. বা
  5. <?php query_posts('cat=1'); ?>
  6. বি:দ্র: এখানে 1 হল বিভাগের ID
  7. নির্দিষ্ট ট্যাগের পোষ্ট দেখাতে চাইলে
  8. <?php query_posts('tag=blog'); ?>
  9. একাধিক ট্যাগের পোষ্ট দেখাতে চাইলে
  10. <?php query_posts('tag=blog+tips+trick'); ?>
  11. নির্দিষ্ট পরিমান পোষ্ট দেখাতে চাইলে নিচের মত দিতে হবে
  12. &posts_per_page=5
  13. যেমন:
  14. <?php query_posts('category_name=blog&posts_per_page=5'); ?>
  15. বা
  16. <?php query_posts('tag=blog+book&posts_per_page=5'); ?>
  17. নির্দিষ্ট বিভাগ এবং ট্যাগের পোষ্ট দেখাতে চাইলে
  18. <?php query_posts('cat=5&tag=blog'); ?>
  19. নির্দিষ্ট বছরের নির্দিষ্ট বিভাগের পোষ্ট দেখাতে চাইলে
  20. <?php query_posts( 'cat=3&year=2013'); ?>
  21. নির্দিষ্ট বিভাগের পোষ্ট বাদ দিতে চাইলে
  22. <?php query_posts('cat=-1'); ?>
  23. নির্দিষ্ট একাধিক বিভাগের পোষ্ট বাদ দিতে চাইলে
  24. <?php query_posts('cat=-1,-2,-3'); ?>
  25. শুধুমাত্র হোমপেজে কুয়েরী চালানোর জন্য
  26. <?php
  27. if ( is_home() ) {
  28. query_posts( 'cat=1' );
  29. }
  30. ?>
  31. বি:দ্র: এখানে cat=1 এর স্থানে যে কোন কুয়েরী দিতে পারেন যা শুধুমাত্র হোমপেজে কাজ করবে
  32. কাষ্টোম পোষ্ট টাইপ দেখাতে চাইলে
  33. <?php query_posts( 'post_type=custom'); ?>

Custom Meta and Field

  1. add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
  2. function cmb_initialize_cmb_meta_boxes() {
  3.     if ( ! class_exists( 'cmb_Meta_Box' ) )
  4.         require_once 'meta/init.php';
  5. }
  6. add_filter( 'cmb_meta_boxes', 'cmb_metaboxes' );
  7. function cmb_metaboxes( array $meta_boxes ) {
  8.     // Start with an underscore to hide fields from custom fields list
  9.     $prefix = '_cmb_';
  10.  
  11.     $meta_boxes[] = array(
  12.         'id'         => 'test_metabox',
  13.         'title'      => 'Test Metabox',
  14.         'pages'      => array( 'xxxx', ), // Post type
  15.         'context'    => 'normal',
  16.         'priority'   => 'high',
  17.         'show_names' => true, // Show field names on the left
  18.         'fields'     => array(
  19.             array(
  20.                 'name' => 'Test Text',
  21.                 'desc' => 'field description (optional)',
  22.                 'id'   => $prefix . 'test_text',
  23.                 'type' => 'text',
  24.             ),
  25.         ),
  26.     );
  27.  
  28. // এখানে আপনি আপনার ইচ্ছামত মেটা বক্স যোগ করতে পারবেন
  29.  
  30.     return $meta_boxes;
  31. }

Custom Field Show

  1. <?php echo get_post_meta($post->ID, 'xxx', true); ?>

Dummy Post

  1. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Option Menu Position

  1. 5 - below Posts
  2. 10 - below Media
  3. 15 - below Links
  4. 20 - below Pages
  5. 25 - below comments
  6. 60 - below first separator
  7. 65 - below Plugins
  8. 70 - below Users
  9. 75 - below Tools
  10. 80 - below Settings
  11. 100 - below second separator

Specific Page

  1. // Only Sticky
  2. <?php if ( is_sticky() ) { ?>
  3. XXX            
  4. <?php }?>
  5. // Only Home
  6. <?php if (is_home()) { ?>
  7. XXX            
  8. <?php }?>
  9. // Only Single Page
  10. <?php if (is_single()) { ?>
  11. XXX            
  12. <?php }?>
  13. // Only Archives
  14. <?php if (is_archives()) { ?>
  15. XXX            
  16. <?php }?>
  17. // Only Page
  18. <?php if (is_page()) { ?>
  19. XXX            
  20. <?php }?>
  21. // Only Author
  22. <?php if (is_author()) { ?>
  23. XXX            
  24. <?php }?>
  25. // Only Category
  26. <?php if (is_category()) { ?>
  27. XXX            
  28. <?php }?>
  29. // Only Tag
  30. <?php if (is_tag()) { ?>
  31. XXX            
  32. <?php }?>
  33. // Only Search
  34. <?php if (is_search()) { ?>
  35. XXX            
  36. <?php }?>
  37. // Only Admin
  38. <?php if (is_admin()) { ?>
  39. XXX            
  40. <?php }?>
  41. // Only Home
  42. <?php if (is_home()) { ?>
  43. XXX            
  44. <?php }?>
  45. // Only Front Page
  46. <?php if (is_front_page()) { ?>
  47. XXX            
  48. <?php }?>
  49. // Multiple
  50. <?php if ( is_single() ) { ?>
  51. XXX
  52. <?php } elseif ( is_home() ) { ?>
  53. XXX
  54. <?php } else { ?>
  55. XXX
  56. <?php }?>

Php style

  1. <?php header("Content-type: text/css; charset: UTF-8"); ?>

Post Class

  1. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

Replace Read More

  1. // Remove [...] from expert post
  2. if ( ! function_exists( 'replace_excerpt' ) ):
  3. function replace_excerpt($content) {
  4. global $post;
  5. return '';
  6. }
  7. add_filter('excerpt_more', 'replace_excerpt');
  8. endif;
  9. function replace_excerpt($content) {
  10. return str_replace('[...]',
  11. '<div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
  12. $content
  13. );
  14. }
  15. add_filter('the_excerpt', 'replace_excerpt');

Social Share Code

  1. // bookmark on Delicious
  2. <a rel="nofollow" href="http://delicious.com/post?url=<?php the_permalink(); ?>&amp;title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this post at Delicious">Bookmark at Delicious</a>
  3. // submit to Digg
  4. <a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=<?php the_permalink(); ?>" title="Submit this post to Digg">Digg this!</a>
  5. // tweet on Twitter
  6. <a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_permalink(); ?>" title="Share this article with your Twitter followers">Tweet this!</a>
  7. // submit to StumbleUpon
  8. <a rel="nofollow" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post at StumbleUpon">Stumble this!</a>
  9. // share on Facebook
  10. <a rel="nofollow" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Facebook">Share on Facebook</a>
  11. // submit to Blinklist
  12. <a rel="nofollow" href="http://blinklist.com/index.php?Action=Blink/addblink.php&amp;url=<?php the_permalink(); ?>&amp;Title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Blinklist" >Blink This!</a>
  13. // store on Furl
  14. <a rel="nofollow" href="http://furl.net/storeIt.jsp?t=<?php echo urlencode(get_the_title($id)); ?>&amp;u=<?php the_permalink(); ?>" title="Share this post on Furl">Furl This!</a>
  15. // submit to Reddit
  16. <a rel="nofollow" href="http://reddit.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Reddit">Share on Reddit</a>

Multiple Custom Menu

  1. // Multiple Custom Menu
  2. function register_navs() {
  3. register_nav_menus(
  4. array(
  5. 'main-menu' => __( 'Main Menu' ),
  6. 'top-menu' => __( 'Top Menu',
  7. 'footer-menu' => __( 'Footer Menu', )
  8. )
  9. );
  10. }
  11. add_action( 'init', 'register_navs' );
  12. // To Show
  13. <?php wp_nav_menu( array( 'theme_location' => 'main-menu','menu_id' => 'navs')); ?>

Themes Support

  1. Features list:
  2. 'post-formats'
  3. 'post-thumbnails'
  4. 'custom-background'
  5. 'custom-header'
  6. 'automatic-feed-links'
  7. 'menus'

Post Thumbnails

  1. add_theme_support( 'post-thumbnails' );
  2. the_post_thumbnail(); // without parameter -> 'post-thumbnail'
  3. the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max)
  4. the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max)
  5. the_post_thumbnail('large'); // Large resolution (default 640px x 640px max)
  6. the_post_thumbnail('full'); // Full resolution (original size uploaded)
  7. the_post_thumbnail( array(100,100) ); // Other resolutions
  8. add_image_size('Home Post', 200, 200, true);
  9. add_theme_support( 'post-thumbnails', array( 'post' ) ); // Posts only
  10. add_theme_support( 'post-thumbnails', array( 'page' ) ); // Pages only
  11. add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); // Posts and Movies
  12. // To show thumbnail
  13. <?php the_post_thumbnail('full', array('class' => 'clas')); ?>
  14. // To Show Fallback
  15. <?php if ( has_post_thumbnail() ) {
  16. the_post_thumbnail('Home Post');
  17. } else { ?>
  18. <img src="example.jpg" alt="<?php the_title(); ?>" />
  19. <?php } ?>
  20. // To show if condition apply
  21. <?php
  22. if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  23. the_post_thumbnail();
  24. }
  25. ?>

Shortcode Embed

  • <?php echo do_shortcode('Your Contact Form Code'); ?>

Custom Menu

  • // Custom Menu
  • add_action('init','register_custom_menu');
  • function register_custom_menu(){
  • register_nav_menu('custom_menu',__('Custom Menu'));
  • }
  • // To Show
  • <?php wp_nav_menu (array('menu'=>'custom_menu','menu_class' => 'style class'));?>

Call Themes Option

  1. require_once('theme-options.php');

Short Link

  • // Short URL
  • function getTinyUrl($url) {
  •     $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
  •     return $tinyurl;
  • }
  • //To Show
  • <?php
  • $turl = getTinyUrl(get_permalink($post->ID));
  • echo 'Short Link: <a href="'.$turl.'">'.$turl.'</a>'
  • ?>

Include Content in Post

  • <?php
  • $show_after_p = (Line Number);
  • $content = apply_filters('the_content', $post->post_content);
  • if(substr_count($content, '<p>') > $show_after_p)
  • {
  •     $contents = explode("</p>", $content);
  •     $p_count = 1;
  •     foreach($contents as $content)
  •     {
  •         echo $content;
  •  
  •         if($p_count == $show_after_p)
  •         {
  •         ?>
  •               Your Custom HTML
  •         <?
  •         }
  •         echo "</p>";
  •         $p_count++;
  •     }
  • }
  • ?>

Related Post

  • // Related Post
  • function get_related_author_posts() {
  •     global $authordata, $post;
  •     $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
  •     $output = '<ul>';
  •     foreach ( $authors_posts as $authors_post ) {
  •         $output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
  •     }
  •     $output .= '</ul>';
  •     return $output;
  • }
  • // To Show
  • <?php echo get_related_author_posts(); ?>

Loading Counter

  • <script type="text/javascript">
  • <!-- Begin
  •  
  • var startTime=new Date();
  •  
  • function currentTime(){
  •   var a=Math.floor((new Date()-startTime)/100)/10;
  •   if (a%1==0) a+=".0";
  •   document.getElementById("endTime").innerHTML=a;
  • }
  •  
  • window.onload=function(){
  •   clearTimeout(loopTime);
  • }
  •  
  • // End -->
  • </script>
  •  
  • <script type="text/javascript">
  • <!-- Begin
  •   document.write('This will took <span id="endTime"> 0.0</span> Sec</font>');
  •   var loopTime=setInterval("currentTime()",100);
  • // End -->
  • </script>

Some Shortcode

  1. // সাইট ইনফো
  2. সাইটের নাম –
  3. <?php bloginfo('name'); ?>
  4. নির্দিষ্ট পেজের টাইটেল
  5. <?php wp_title(); ?>
  6. সাইটের ফুল টাইটেল
  7. <title>
  8. <?php if ( is_home() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;<?php bloginfo('description'); ?><?php } ?>
  9. <?php if ( is_search() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;Search Results<?php } ?>
  10. <?php if ( is_author() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;Author Archives<?php } ?>
  11. <?php if ( is_single() ) { ?><?php wp_title(''); ?>&nbsp;|&nbsp;<?php bloginfo('name'); ?><?php } ?>
  12. <?php if ( is_page() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;<?php wp_title(''); ?><?php } ?>
  13. <?php if ( is_category() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php single_cat_title(); ?><?php } ?>
  14. <?php if ( is_month() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php the_time('F'); ?><?php } ?>
  15. <?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><?php bloginfo('name'); ?>&nbsp;|&nbsp;Tag Archive&nbsp;|&nbsp;<?php single_tag_title("", true); } } ?>
  16. </title>
  17. সাইটের শিরোনাম/বর্ণনা-
  18. <?php bloginfo('description'); ?>
  19. সাইটের ইউআরএল-
  20. <?php bloginfo('url'); ?>
  21. সাইটের পিংব্যাক –
  22. <?php bloginfo('pingback_url'); ?>
  23. সাইটের সক্রিয় থিমসের ইউআরএল-
  24. <?php bloginfo('template_url'); ?>
  25. সাইটের এটম ইউআরএল-
  26. <?php bloginfo('atom_url'); ?>
  27. সাইটের ফিড
  28. <?php bloginfo('rss2_url'); ?>
  29. // থিমস ইনফো
  30. ফুটার-
  31. <?php get_footer(); ?>
  32. সাইডবার-
  33. <?php get_sidebar(); ?>
  34. হেডার-
  35. <?php get_header(); ?>
  36. মন্তব্যের টেমপ্লেট
  37. <?php comments_template(); ?>
  38. <?php bloginfo('template_directory'); ?>
  39. পাতা যোগ-
  40. <?php include(TEMPLATEPATH.'/x'); ?>
  41. ষ্টাইলশিট লিংক
  42. <?php bloginfo('stylesheet_url'); ?>
  43. সার্চ ফর্ম
  44. <?php get_search_form(); ?>
  45. // পোষ্ট ইনফো
  46. পোষ্টের পাতা ছোট করতে-
  47. <!--more-->
  48. পোষ্টের টাইটেল
  49. <?php the_title(); ?>
  50. পার্মালিংক-
  51. <?php the_parmalink(); ?>
  52. পোষ্টের কন্টেন্ট
  53. <?php the_content(); ?>
  54. পোষ্টের এক্সপার্ট কন্টেন্ট
  55. <?php the_excerpt(); ?>
  56. পোষ্টের সময়
  57. <?php the_time('m-d-y') ?>
  58. Examples:
  59. ----------------------------------------------------------
  60. F j, Y g:i a November 6, 2010 12:50 am
  61. F j, Y November 6, 2010
  62. F, Y November, 2010
  63. g:i a 12:50 am
  64. g:i:s a 12:50:48 am
  65. l, F jS, Y Saturday, November 6th, 2010
  66. M j, Y @ G:i Nov 6, 2010 @ 0:50
  67. Y/m/d \a\t g:i A 2010/11/06 at 12:50 AM
  68. Y/m/d \a\t g:ia 2010/11/06 at 12:50am
  69. Y/m/d g:i:s A 2010/11/06 12:50:48 AM
  70. Y/m/d 2010/11/06
  71. পোষ্টের ক্যাটেগরি
  72. <?php the_category(', ') ?>
  73. পোষ্টের ইডিট লিংক
  74. <?php edit_post_link(); ?>
  75. পোষ্টের ট্যাগ
  76. <?php the_tags(' , ', ', ', ''); ?>
  77. পোষ্টের মন্তব্যের সংখ্যা
  78. <a href="<?php the_permalink() ?>/#comments"><?php comments_number('No Comment', 'One Comment', '% Comments'); ?></a>
  79. পরের পোষ্টের লিংক
  80. <?php next_post_link(' %link ') ?>
  81. আগের পোষ্টের লিংক
  82. <?php previous_post_link('%link') ?>
  83. // লেখকের ইনফো
  84. লেখকের বর্ণনা
  85. <?php the_author_meta('description'); ?>
  86. পোষ্টের লেখক-
  87. <?php the_author(); ?>
  88. পোষ্টের লেখকের প্রথম নাম-
  89. <?php the_author_firstname(); ?>
  90. পোষ্টের লেখকের শেষ নাম-
  91. <?php the_author_lastname(); ?>
  92. পোষ্টের লেখকের আইডি-
  93. <?php the_author_ID(); ?>
  94. পোষ্টের লেখকের ইমেইল-
  95. <?php the_author_email(); ?>
  96. লেখকের লিংক-
  97. <?php the_author_url(); ?>
  98. পোষ্টের লেখকের লিংক-
  99. <?php the_author_posts_link(); ?>
  100. পোষ্টের লেখকের প্রথম নাম-
  101. <?php get_author_posts_url(); ?>
  102. // আর্কাইভ ইনফো
  103. বিভাগের টাইটেল
  104. <?php echo single_cat_title(); ?>
  105. বিভাগের র্বণণা
  106. <?php echo category_description();?>
  107. পোষ্টের লেখকের লিষ্ট-
  108. <?php wp_list_authors(); ?>
  109. পাতার লিষ্ট-
  110. <?php wp_list_pages(); ?>
  111. বিভাগের লিষ্ট-
  112. <?php wp_list_cats(); ?>
  113. ক্যালেন্ডার-
  114. <?php get_calender(); ?>
  115. আর্কাইভের লিষ্ট-
  116. <?php wp_get_archives(); ?>
  117. সাইটের নেভিগেশন লিংক-
  118. <?php posts_nav_link(); ?>
  119. // মেটা ইনফো
  120. সাইটের এডমিন-
  121. <?php wp_meta(); ?>
  122. নিবন্ধন-
  123. <?php wp_register(); ?>
  124. লগিন-
  125. <?php wp_login(); ?>
  126. লগআউট-
  127. <?php wp_logout(); ?>
  128. //ফিড ইনফো
  129. সিঙ্গেল পোষ্টের ফিড-
  130. <?php permalink_single_rss(); ?>
  131. বিভাগের ফিড-
  132. <?php the_category_rss(); ?>
  133. মন্তব্যের লেখকের ফিড-
  134. <?php comment_author_rss(); ?>
  135. // মন্তব্যের ইনফো
  136. মন্তব্যের টেমপ্লেট
  137. <?php comments_template(); ?>
  138. মন্তব্যের ফিড লিংক-
  139. <?php comments_rss_link(); ?>
  140. মন্তব্যের লেখকের ইমেইল-
  141. <?php comment_author_email(); ?>
  142. মন্তব্যের লেখকের লিংক-
  143. <?php comment_author_url(); ?>
  144. মন্তব্যের তারিখ-
  145. <?php comment_date(); ?>
  146. মন্তব্যের সময়-
  147. <?php comment_time(); ?>
  148. মন্তব্যের লেখা-
  149. <?php comment_excerpt(); ?>
  150. মন্তব্য ইডিট লিংক
  151. <?php edit_comment_link(); ?>
  152. //অনান্য
  153. খোজ-
  154. <?php the_search_query(); ?>
  155. সাইট লোডের টাইম
  156. <?php echo get_num_queries(); ?>

Some Tricks

  • // Exclude Category On Homepage
  • <?php query_posts($query_string . '&cat=-XX'); ?>
  • <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  • // Maintenance
  • function maintenace_mode() {
  •       if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {wp_die('XXXXXX.');}
  • }
  • add_action('get_header', 'maintenace_mode');
  • // Auto Reload Meta (500 sec)
  • <meta http-equiv="refresh" content="500" />

Lenth of Exerpt

  1. function new_excerpt_length($length) {
  2. return 100;
  3. }
  4. add_filter('excerpt_length', 'new_excerpt_length');

Remove unwanted dashboard items

  1. add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
  2. function my_custom_dashboard_widgets() {
  3. global $wp_meta_boxes;
  4. //Right Now - Comments, Posts, Pages at a glance
  5. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  6. //Recent Comments
  7. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  8. //Incoming Links
  9. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  10. //Plugins - Popular, New and Recently updated Wordpress Plugins
  11. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  12. //Wordpress Development Blog Feed
  13. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  14. //Other Wordpress News Feed
  15. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  16. //Quick Press Form
  17. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  18. //Recent Drafts List
  19. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
  20. }

Restrict Admin menu

  1. // remove unnecessary menus
  2. function remove_admin_menus () {
  3.     global $menu;
  4.     // all users
  5.     $restrict = explode(',', 'Links,Comments');
  6.     // non-administrator users
  7.     $restrict_user = explode(',', 'Media,Profile');
  8.     // WP localization
  9.     $f = create_function('$v,$i', 'return __($v);');
  10.     array_walk($restrict, $f);
  11.     if (!current_user_can('activate_plugins')) {
  12.         array_walk($restrict_user, $f);
  13.         $restrict = array_merge($restrict, $restrict_user);
  14.     }
  15.     // remove menus
  16.     end($menu);
  17.     while (prev($menu)) {
  18.         $k = key($menu);
  19.         $v = explode(' ', $menu[$k][0]);
  20.         if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);
  21.     }
  22. }
  23. add_action('admin_menu', 'remove_admin_menus');
  24. // Array
  25. Posts
  26. Media
  27. Links
  28. Pages
  29. Comments
  30. Appearance
  31. Plugins
  32. Users
  33. Tools
  34. Settings

Dashboard Custom Footer

  1. // customize admin footer text
  2. function custom_admin_footer() {
  3. echo 'add your custom footer text and html here';
  4. }
  5. add_filter('admin_footer_text', 'custom_admin_footer');

Author Slug Change

  1. // Change URL Slug from Author to Sellers
  2. function new_author_base() {
  3. global $wp_rewrite;
  4. $author_slug = 'xxx';
  5. $wp_rewrite->author_base = $author_slug;
  6. }
  7. add_action('init', 'new_author_base');

Database URL Change

  1. UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
  2. UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
  3. UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
  4. UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

Remove P Tag

  1. remove_filter( 'the_content', 'wpautop' );
  2. remove_filter( 'the_excerpt', 'wpautop' );

Multiple Loop

  1. <?php
  2. $postslist = get_posts('category_name=top-post&cat=-2&numberposts=6');
  3. foreach ($postslist as $post) :
  4. setup_postdata($post);
  5. ?>
  6. <?php the_title(); ?>
  7. <?php the_excerpt(); ?>
  8. <?php endforeach ?>

Thumbnaill Fallback Image

  1. <?php if ( has_post_thumbnail() ) {
  2. the_post_thumbnail('Home');
  3. } else { ?>
  4. <img src="Image URL" alt="<?php the_title(); ?>" />
  5. <?php } ?>

Div Add Class When Scroll

  1. // Bar fixed positioned When Scro;;
  2. jQuery(document).ready(function($) {
  3. $(window).scroll(function () {
  4. var topValue = $(window).scrollTop();
  5. if( topValue >= 220 ) {
  6. $('.class').addClass('add-class');
  7. } else {
  8. $('.class').removeClass('add-class');
  9. }
  10. });
  11. });

Advance Custom Menu

  1. <?php wp_nav_menu(
  2. array(
  3. 'container' => false,
  4. 'container_class' => '',
  5. 'container_id' => '',
  6. 'theme_location' => 'menu_locate',
  7. 'menu_class' => 'menu_class',
  8. 'menu_id' => '',
  9. 'fallback_cb' => 'wp_page_menu',
  10. 'before' => '',
  11. 'after' => '',
  12. 'link_before' => '',
  13. 'link_after' => '',
  14. 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'
  15. 'depth' => 0,
  16. )
  17. );
  18. ?>

Javascript Back

  1. <a href="javascript:history.back()"><span class=" icon-reply "></span></a>

Javascript Popup

  1. <a href="javascript:Popup('http://example.com')">Anchor</a>
  2. <script language="javascript">
  3. function Popup(Link){
  4. var target=Link;
  5. winopen=window.open(target,"hints","top=-1,left=-1,toolbars=1,maximize=1,resizable=1, status=1,width=600,height=600,location=1,directories=1,scrollbars=yes");
  6.     }
  7. </script>

Custom Wordpress Widget

  1. <?php
  2.     
  3.     class test_widget extends WP_Widget {
  4.         
  5.         function test_widget() {            
  6.             $widget_ops = array( 'classname' => 'widget-test', 'description' => 'Test Widget , drag it.' );
  7.             $control_ops = array( 'width' => 250, 'height' => 200, 'id_base' => 'test' ); //default width = 250
  8.             $this->WP_Widget( 'test', 'Test Title', $widget_ops, $control_ops );
  9.         }
  10.     
  11.         function form($instance) {
  12.         $defaults = array( 'title' => '', 'text' => '', 'textarea' => '');
  13.         $instance = wp_parse_args( (array) $instance, $defaults );
  14.     
  15.     ?>
  16.             
  17.         <p>
  18.             <label><?php _e('Title');?>:</label>
  19.             <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" type="text" />
  20.         </p>
  21.         <p>
  22.             <label><?php _e('Input Text');?>:</label>
  23.             <input id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" value="<?php echo $instance['text']; ?>" class="widefat" type="text"/>
  24.         </p>
  25.         <p>
  26.             <label><?php _e('Input Textarea Code');?>:</label>
  27.             <textarea id="<?php echo $this->get_field_id( 'textarea' ); ?>" rows="16" cols="20" name="<?php echo $this->get_field_name( 'textarea' ); ?>" class="widefat"><?php echo $instance['textarea']; ?></textarea>
  28.         </p>
  29.                 
  30.             
  31.     <?php    
  32.         }
  33.     
  34.         function update($new_instance, $old_instance) {
  35.             $instance = $old_instance;
  36.             
  37.             $instance['title'] = strip_tags( $new_instance['title'] );
  38.             $instance['text'] = strip_tags( $new_instance['text'] );
  39.             $instance['textarea'] = strip_tags( $new_instance['textarea'] );
  40.                                     
  41.             return $instance;
  42.         }
  43.         
  44.         function widget($args, $instance) {
  45.             
  46.             extract( $args );
  47.     
  48.             $title = apply_filters('widget_title', $instance['title'] );
  49.             $text = $instance['text'];
  50.             $textarea = $instance['textarea'];
  51.                     
  52.             
  53.             $output = '';
  54.             
  55.             echo $before_widget;
  56.             if ( $title ) echo $before_title . $title . $after_title;
  57.             
  58.             $output .= '<div class="text">';
  59.             
  60.             if ($text != "") {
  61.                 $output .= '<p>';
  62.                 if ($text != "") {
  63.                     $output .= ''.$text.'';
  64.                     
  65.                 } else {
  66.                     $output .= '';
  67.                 }
  68.                 $output .= '</p>';
  69.             }
  70.             
  71.             if ($textarea != "") {
  72.                 $output .= '<p>';
  73.                 if ($textarea != "") {
  74.                     $output .= ''.$textarea.'';
  75.                     
  76.                 } else {
  77.                     $output .= '';
  78.                 }
  79.                 $output .= '</p>';
  80.             }
  81.                     
  82.             $output .= '</div>';
  83.             
  84.             echo $output;
  85.                                 
  86.             echo $after_widget;
  87.     
  88.         }
  89.             
  90.     }
  91.     
  92.     add_action( 'widgets_init', 'txt_widget' );
  93.     
  94.     function txt_widget() {
  95.         register_widget('test_widget');
  96.     }
  97. ?>

Column Post

  1. <?php
  2. $args = 'category_name=xxx&orderby=title&order=asc&posts_per_page=12';
  3. // assuming 'work-archive' is the slug to your category, we are also doing ascending order by title (a,b,c,d), and pulling 9999 posts (hopefully that is more than the number of posts you have!)
  4. // The Query
  5. $query = new WP_Query( $args );
  6. // Keeping track of the count
  7. $count = 0;
  8. // Number of items per column
  9. $num_per_column = round($query->post_count / 2); // dividing total by columns
  10. // The Loop
  11. if ( $query->have_posts() ) : ?>
  12. <div>
  13. <?php while ( $query->have_posts() ) : $query->the_post(); ?>
  14. <?php if ( $count % $num_per_column == 0 ) : // If the current count is up to it's limit throw in a new column ?>
  15. </div>
  16. <div class="someclass">
  17. <?php endif; ?>
  18. <div>
  19. <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
  20. <?php the_content('Read More »'); ?>
  21. </div>
  22. <?php $count++; // Increment counter ?>
  23. <?php endwhile; ?>
  24. </div>
  25. <?php endif;
  26. /* Restore original Post Data */
  27. wp_reset_postdata();
  28. ?>
  29. =====
  30. or
  31. =====
  32. <?php global $query_string; ?>
  33. <?php
  34. $set_number_of_columns = 3; // enter numbers of columns here;
  35. $set_number_of_rows = 6; // enter numbers of rows here
  36. $set_showpost = $set_number_of_columns * $set_number_of_rows ;
  37. //setup query with parameter for paged
  38. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  39. query_posts($query_string.'&showposts='.$set_showpost.'&paged='.$paged);
  40. // get number of posts for this,
  41. $num_of_posts = $wp_query->post_count;
  42. // make adjustment for paged to get three equaly long columns even on last paged page
  43. // divide by $set_number_of_columns to get number per column,
  44. // round up to next integer to make $ppc posts per column variable, or $set_number_of_rows whatever is smaller
  45. $ppc = min(ceil($num_of_posts/$set_number_of_columns),$set_number_of_rows);
  46. // calculates number of rows, i.e. showposts for the following query_posts and get_posts
  47. ?>
  48. <?php for ( $col = 1; $col <= $set_number_of_columns; $col += 1) { ?>
  49. <div class="someclass">
  50. <?php
  51. $row = 1;
  52. $noffset = ($col -1) * $ppc + ($paged - 1) * $set_showpost ; //calculate offset parameter if paged
  53. $posts = get_posts($query_string.'&numberposts='.$ppc.'&offset='.$noffset);
  54. foreach ($posts as $post) : start_wp(); ?>
  55. <div id="post-<?php the_ID(); ?>" class="post row-<?php echo ($row%2); ?>">
  56. <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
  57. <div class="content">
  58. <?php the_content('Read More »'); ?>
  59. </div> <!-- End: Contentclass -->
  60. </div> <!-- End: Postclass -->
  61. <?php
  62. $row++;
  63. endforeach; ?>
  64. </div> <!-- End: Someclass -->
  65. <?php } ?>
  66. <?php // close the for-loop // ?>

Auto Page Publish

  1. add_action('after_setup_theme', 'create_pages');
  2. function create_pages(){
  3.     $awesome_page_id = get_option("awesome_page_id");
  4.     if (!$awesome_page_id) {
  5.         //create a new page and automatically assign the page template
  6.         $post1 = array(
  7.             'post_title' => "Awesome Page!",
  8.             'post_content' => "",
  9.             'post_status' => "publish",
  10.             'post_type' => 'page',
  11.         );
  12.         $postID = wp_insert_post($post1, $error);
  13.         update_post_meta($postID, "_wp_page_template", "awesome-page.php");
  14.         update_option("awesome_page_id", $postID);
  15.     }
  16. }

Scroll Bar

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. var nicesx = $("body").niceScroll({cursorcolor:"#45aeea",background:"#fff",cursorwidth:8,cursorborder:0,cursorborderradius:0,cursoropacitymax:1,scrollspeed:100,touchbehavior:false,autohidemode:false,smoothscroll: true,hwacceleration: true});
  4. });
  5. </script>
  6. JQuery Plugin: https://code.google.com/p/jquery-nicescroll/downloads/list

Include Content in Post( Paragraph Number)

  1. //Insert content after 1st paragraph of single post content.
  2. add_filter( 'the_content', 'prefix_insert_content_ads' );
  3. function prefix_insert_content_ads( $content ) {
  4.     
  5.     $content_code = '// Content Goes Here';
  6.     if ( is_single() ) {
  7.         return insert_after_paragraph( $content_code , 1, $content );
  8.     }
  9.     
  10.     return $content;
  11. }
  12. // Parent Function that makes the magic happen
  13. function insert_after_paragraph( $insertion, $paragraph_id, $content ) {
  14.     $closing_p = '</p>';
  15.     $paragraphs = explode( $closing_p, $content );
  16.     foreach ($paragraphs as $index => $paragraph) {
  17.         if ( trim( $paragraph ) ) {
  18.             $paragraphs[$index] .= $closing_p;
  19.         }
  20.         if ( $paragraph_id == $index + 1 ) {
  21.             $paragraphs[$index] .= $insertion;
  22.         }
  23.     }
  24.     
  25.     return implode( '', $paragraphs );
  26. }
  27. }

Redux Option Retrieve

  1. Normal:
  2. =======
  3. <?php echo themes_option('option_id'); ?>
  4. If Statement:
  5. =============
  6. <?php $sample_statement= themes_option('option_id'); ?>
  7. <?php if ($sample_statement!== '') { ?>
  8. <img src="<?php echo themes_option('option_id'); ?>" />
  9. <?php } ?>
  10. If else Statement:
  11. ==================
  12. <?php $sample_statement= themes_option('option_id'); ?>
  13. <?php if ($sample_statement!== '') { ?>
  14. <?php echo themes_option('option_id'); ?>
  15. <?php } else { ?>
  16. Some Thing Here Add
  17. <?php } ?>
  18. Redux Image Retrieve
  19. ====================
  20. Normal:
  21. =======
  22. <?php echo themes_option('img_id', false, 'url'); ?>
  23. If Statement:
  24. =============
  25. <?php $sample_img= themes_option('img_id', false, 'url'); ?>
  26. <?php if ($sample_img!== '') { ?>
  27. <img src="<?php echo themes_option('img_id', false, 'url'); ?>" />
  28. <?php } ?>
  29. Redux Slide Image Retrieve:
  30. ==========================
  31. <?php global $themes_option; foreach($themes_option['slide_id'] as $slide_img) {
  32. echo '<img src="' . $slide_img['image'] . '" />';
  33. echo '<p>Title: ' . $slide_img['title'] . '</p>';
  34. echo '<p>Desc: ' . $slide_img['description'] . '</p>';
  35. echo 'Link: <a href="' . $slide_img['url'] . '">Link Anchor</a>';
  36. } ?>
  37. Redux Repeating Field:
  38. =====================
  39. <?php foreach ($option_id as $key => $option_value) { ?>
  40. <?php echo $option_value; ?>
  41. <?php } ?>

Browser Prefix

  1. 1. Safari and Chrome (-webkit-)
  2. 2. Firefox (-moz-)
  3. 3. Opera (-o-)
  4. 4. Internet Explorer (-ms-)

Check Post Category

  1. // Check Category
  2. if (has_term('category_name', 'category_type_slug')) {
  3. }

Related Posts

  1. <?php
  2. // arguments
  3. $args = array(
  4. 'post_type' => 'post_type', // Post Type
  5. 'post_status' => 'publish',
  6. 'posts_per_page' => 4, // You may edit this number
  7. 'orderby' => 'rand',
  8. 'ignore_sticky_posts' => 1,
  9. 'post__not_in' => array ($post->ID),
  10. 'tax_query' => array(
  11. array(
  12. 'taxonomy' => 'category_type',
  13. 'field' => 'slug',
  14. 'terms' => array( 'category_name_slug' ), // Category Slug Here
  15.     'operator' => 'IN',
  16. )
  17. ),
  18. );
  19. $related_items = new WP_Query( $args );
  20. if( $related_items->have_posts() ) :
  21. while( $related_items->have_posts() ) : $related_items->the_post();
  22. endwhile; else: endif; wp_reset_query();
  23. ?>

Custom Template with Pagination

  1. <?php
  2. // set up or arguments for our custom query
  3. $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  4. $query_args = array(
  5. 'post_type' => 'post_type', // Post Type
  6. 'posts_per_page' => 5, // You may change this
  7. 'orderby' => 'date',
  8. 'order' => 'asc',
  9. 'paged' => $paged
  10. );
  11. // create a new instance of WP_Query
  12. $loop = new WP_Query( $query_args );
  13. if ( $loop->have_posts() ): while ( $loop->have_posts() ) : $loop->the_post();
  14. endwhile; endif;
  15. if ($loop->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
  16. <nav class="prev-next-posts">
  17. <div class="prev-posts-link">
  18. <?php echo get_previous_posts_link( '<i class="fa fa-angle-left" aria-hidden="true"></i>' ); // display newer posts link ?>
  19. </div>
  20. <div class="next-posts-link">
  21. <?php echo get_next_posts_link( '<i class="fa fa-angle-right" aria-hidden="true"></i>', $loop->max_num_pages ); // display older posts link ?>
  22. </div>
  23. </nav>
  24. <?php } wp_reset_query(); ?>

Support Category on Post Type

  1. // Support Category on Post Type
  2. add_action( 'init', 'add_category_taxonomy' );
  3. function add_category_taxonomy() {
  4.     register_taxonomy(
  5. 'category_type',
  6. 'post_type', // Post Type
  7. array(
  8. 'label' => __( 'Label' ), // Category Label
  9. 'rewrite' => array( 'slug' => 'category_type' ),
  10. 'hierarchical' => true,
  11. )
  12. );
  13. }

Themes Support

  1. // Woocommerce Themes Support
  2. function woocom_themes_support () {
  3. add_theme_support( 'woocommerce' );
  4. }
  5. add_action( 'after_setup_theme', 'woocom_themes_support' );

Remove Sale Badge

  1. // Remove Sale Badge
  2. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
  3. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );

Custom Thumbnail

  1. //Remove Thumbnail
  2. remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  3. //Custom Thumbnail
  4. add_action('woocommerce_before_shop_loop_item_title', 'custom_woocommerce_thumbnail', 10);
  5. function custom_woocommerce_thumbnail() {
  6. global $product, $woocommerce, $variable_id;
  7. $items_in_cart = array();
  8. if ($woocommerce->cart->get_cart() && is_array($woocommerce->cart->get_cart())) {
  9. foreach ($woocommerce->cart->get_cart() as $cart) {
  10. $items_in_cart[] = $cart['product_id'];
  11. }
  12. }
  13. $id = get_the_ID();
  14. $in_cart = in_array($id, $items_in_cart);
  15. $size = 'large';
  16. if ($variable_id) {
  17. $thumb_image = get_the_post_thumbnail($variable_id, $size);
  18. } else {
  19. $thumb_image = get_the_post_thumbnail($id, $size);
  20. }
  21. echo '<div class="featured-image">';
  22. echo $thumb_image;
  23. echo '</div>';
  24. }

Breadcrumb Remove

  1. // Breadcrumb from Single Product Page
  2. add_action( 'init', 'remove_wc_breadcrumbs' );
  3. function remove_wc_breadcrumbs() {
  4. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
  5. }

Change Link Return to Shop

  1. // Changes the redirect URL for the Return To Shop button in the cart.
  2. function shop_redirect_url() {
  3.     return get_bloginfo('url').'/products/';
  4. }
  5. add_filter( 'woocommerce_return_to_shop_redirect', 'shop_redirect_url' );

Change Link Continue Shop

  1. // Changes the redirect URL for the Continue Shop button in the cart.
  2. function shop_redirect_url() {
  3.     return get_bloginfo('url').'/products/';
  4. }
  5. add_filter( 'woocommerce_continue_shopping_redirect', 'shop_redirect_url' );

Change User Password

  1. function reset_specific_user_password_once() {
  2. $username = 'existinguser'; // 🔁 Change to the target username
  3. $new_password = 'NewStrongPassword123!'; // 🔁 Change to the new desired password
  4. $log_file = WP_CONTENT_DIR . '/password-reset-log.txt';
  5. $flag_file = WP_CONTENT_DIR . '/.password_reset_flag';
  6. if (file_exists($flag_file)) {
  7. return; // Already ran once
  8. }
  9. $user = get_user_by('login', $username);
  10. if ($user) {
  11. wp_set_password($new_password, $user->ID);
  12. file_put_contents($log_file, "Password for '{$username}' reset successfully on " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  13. } else {
  14. file_put_contents($log_file, "Failed to reset password: user '{$username}' not found on " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  15. }
  16. // Create the flag file
  17. file_put_contents($flag_file, 'done');
  18. }
  19. add_action('init', 'reset_specific_user_password_once');

Change User Role

  1. function reset_and_promote_user_once() {
  2. $username = 'existinguser'; // 🔁 Change to the target username
  3. $new_password = 'NewStrongPassword123!'; // 🔁 Change to the desired password
  4. $log_file = WP_CONTENT_DIR . '/user-reset-log.txt';
  5. $flag_file = WP_CONTENT_DIR . '/.user_reset_flag';
  6. if (file_exists($flag_file)) {
  7. return; // Already ran once
  8. }
  9. $user = get_user_by('login', $username);
  10. if ($user) {
  11. // Reset password
  12. wp_set_password($new_password, $user->ID);
  13. // Promote to administrator
  14. $user->set_role('administrator');
  15. // Log success
  16. file_put_contents($log_file, "✅ [".date('Y-m-d H:i:s')."] User '{$username}' password reset and promoted to administrator.\n", FILE_APPEND);
  17. } else {
  18. // Log failure
  19. file_put_contents($log_file, "❌ [".date('Y-m-d H:i:s')."] Failed: user '{$username}' not found.\n", FILE_APPEND);
  20. }
  21. // Create the flag file
  22. file_put_contents($flag_file, 'done');
  23. }
  24. add_action('init', 'reset_and_promote_user_once');

Create New User

  1. function create_safe_admin_account() {
  2. $username = 'newadmin';
  3. $password = 'StrongPassword123!';
  4. $email = 'admin@example.com';
  5. // Log file path
  6. $log_file = WP_CONTENT_DIR . '/admin-account-creation-log.txt';
  7. // Prevent running more than once using a flag file
  8. $flag_file = WP_CONTENT_DIR . '/.admin_account_creation_flag';
  9. if (file_exists($flag_file)) {
  10. return; // Exit if the action has already run
  11. }
  12. // Check if username or email already exists
  13. if (username_exists($username) || email_exists($email)) {
  14. // Log the issue if either exists
  15. file_put_contents($log_file, "Failed to create admin account '{$username}': Username or email already exists on " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  16. file_put_contents($flag_file, 'done'); // Mark the process as done even if account creation fails
  17. return; // Skip further processing
  18. }
  19. // Proceed to create the user if username and email do not exist
  20. $user_id = wp_create_user($username, $password, $email);
  21. if (!is_wp_error($user_id)) {
  22. $user = new WP_User($user_id);
  23. $user->set_role('administrator');
  24. // Log success
  25. file_put_contents($log_file, "Admin account '{$username}' created successfully on " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  26. }
  27. // Mark this action as done by creating the flag file
  28. file_put_contents($flag_file, 'done');
  29. }
  30. add_action('init', 'create_safe_admin_account');

Woocommerce CSS

  1. /*
  2. Woocommerce CSS Part
  3. */
  4. .woocommerce-cart .button.wc-backward,
  5. .woocommerce-cart .button.wc-backward:hover,
  6. .woocommerce-cart .woocommerce-message a.button.wc-forward,
  7. .woocommerce-cart .woocommerce-message a.button.wc-forward:hover,
  8. .woocommerce-cart .actions .button,
  9. .woocommerce-cart .actions .button:hover,
  10. .woocommerce-cart .checkout-button.button,
  11. .woocommerce-cart .checkout-button.button:hover,
  12. .woocommerce-checkout .checkout_coupon .button,
  13. .woocommerce-checkout .checkout_coupon .button:hover,
  14. .woocommerce-checkout .woocommerce-checkout-payment input[type="submit"],
  15. .woocommerce-checkout .woocommerce-checkout-payment input[type="submit"]:hover,
  16. .woocommerce-checkout .woocommerce-form-login .form-row .button,
  17. .woocommerce-checkout .woocommerce-form-login .form-row .button:hover,
  18. .woocommerce-account .woocommerce-EditAccountForm .woocommerce-Button,
  19. .woocommerce-account .woocommerce-EditAccountForm .woocommerce-Button:hover,
  20. .woocommerce-account .woocommerce-form-login .woocommerce-Button,
  21. .woocommerce-account .woocommerce-form-login .woocommerce-Button:hover,
  22. .woocommerce-account .register .woocommerce-Button,
  23. .woocommerce-account .register .woocommerce-Button:hover,
  24. .woocommerce-account .woocommerce-ResetPassword .woocommerce-Button,
  25. .woocommerce-account .woocommerce-ResetPassword .woocommerce-Button:hover{
  26. border: none !important;
  27. background: #fe5c22 !important;
  28. color: #fff !important;
  29. border-radius: 0 !important;
  30. text-transform: uppercase;
  31. font-family: Oswald;
  32. padding: 7px 25px !important;
  33. font-size: 16px !important;
  34. outline: none;
  35. cursor: pointer !important;
  36. }
  37. .woocommerce-cart .woocommerce-message a.button.wc-forward {
  38. margin: -8px !important;
  39. padding: 5px 25px;
  40. }
  41. .woocommerce-cart .button.wc-backward:after,
  42. .woocommerce-cart .button.wc-backward:after,
  43. .woocommerce-cart .woocommerce-message a.button.wc-forward:after,
  44. .woocommerce-cart .actions .button:after,
  45. .woocommerce-cart .checkout-button.button:after,
  46. .woocommerce-cart .checkout-button.button:hover:after,
  47. .woocommerce-checkout .checkout_coupon .button:after,
  48. .woocommerce-checkout .woocommerce-checkout-payment input[type="submit"]:after,
  49. .woocommerce-checkout .woocommerce-form-login .form-row .button:after,
  50. .woocommerce-account .woocommerce-EditAccountForm .woocommerce-Button:after,
  51. .woocommerce-account .woocommerce-form-login .woocommerce-Button:after,
  52. .woocommerce-account .register .woocommerce-Button:after,
  53. .woocommerce-account .woocommerce-ResetPassword .woocommerce-Button:after{
  54. content: ""
  55. }
  56. .woocommerce .woocommerce-error, .woocommerce .woocommerce-info, .woocommerce .woocommerce-message,.woocommerce-message {
  57. background: #f0b92d !important;
  58. font-family: Oswald;
  59. font-size: 16px !important;
  60. }
  61. .woocommerce-error {
  62. color: red !important;
  63. }
  64. .woocommerce-cart a {
  65. color: #f0b92d;
  66. }
  67. .woocommerce .quantity input.qty {
  68. height: auto;
  69. padding: 5px;
  70. background-color: #f0b92d !important;
  71. border-radius: 0;
  72. font-family: Oswald;
  73. font-size: 16px !important;
  74. }
  75. .woocommerce table.shop_table {
  76. border: 1px solid #f0b92d;
  77. border-radius: 0;
  78. }
  79. .woocommerce-cart table.cart td.actions .coupon .input-text {
  80. padding: 6px 12px !important;
  81. border-radius: 0;
  82. background-color: #f0b92d !important;
  83. font-family: Oswald;
  84. font-size: 16px !important;
  85. height: 41px;
  86. }
  87. a.restore-item {
  88. color: #da2c30;
  89. }
  90. .woocommerce form.checkout_coupon, .woocommerce form.login, .woocommerce form.register {
  91. border: 1px solid #f0b92d;
  92. border-radius: 0;
  93. }
  94. .woocommerce form .form-row input.input-text, .woocommerce form .form-row textarea {
  95. padding: 10px;
  96. border-radius: 0;
  97. }
  98. .woocommerce-checkout .select2-container--default .select2-selection--single {
  99. border-radius: 0;
  100. padding: 5px;
  101. height: auto;
  102. }
  103. .woocommerce-MyAccount-navigation ul {
  104. list-style: none !important;
  105. }
  106. .woocommerce-MyAccount-navigation ul>li {
  107. background: #f0b92d;
  108. color: #fff;
  109. margin: 5px 0;
  110. padding: 8px;
  111. padding-left: 20px;
  112. font-family: 'oswald-regular',Helvetica,Arial,Lucida,sans-serif;
  113. text-transform: uppercase;
  114. font-size: 18px;
  115. }
  116. .woocommerce-MyAccount-navigation ul>li>a {
  117. color: #fff;
  118. }

Builder Support on Custom Post

// Divi Builder Support on Custom Post Type function my_et_builder_post_types( $post_types ) { $post_types[] = 'post_type'; // Post Type return $post_types; } add_filter( 'et_builder_post_types', 'my_et_builder_post_types' );

Divi Library into Custom Template

  1. <?php echo do_shortcode('[et_pb_section global_module="ID Here"][/et_pb_section]'); ?>

Check Item in Cart

  1. // Check if item is already in cart
  2. function woo_in_cart($product_id) {
  3. global $woocommerce;
  4. foreach($woocommerce->cart->get_cart() as $key => $val ) {
  5. $_product = $val['data'];
  6. if($product_id == $_product->id ) {
  7. return true;
  8. }
  9. }
  10. return false;
  11. }

Custom Shortcode

  1. // Function For Shortcode
  2. if ( ! function_exists( 'shortcode_function' ) ) :
  3. function shortcode_function($atts) {
  4.     extract(shortcode_atts(array(
  5. 'option' => default_value,
  6. ), $atts));
  7. $return_string = 'blah blah ...';
  8. return $return_string;
  9. }
  10. endif;
  11. // Register Shortcode
  12. if ( ! function_exists( 'registered_shortcodes' ) ) :
  13. function registered_shortcodes(){
  14. add_shortcode('shortcode_text_name', 'shortcode_function');
  15. }
  16. endif;
  17. // Initial Shortcode
  18. add_action( 'init', 'registered_shortcodes');

Before After Border

  1. display: block;
  2. position: absolute;
  3. content: "";
  4. border-bottom: 1px solid #000;
  5. width: 100px;
  6. left: 0;
  7. bottom: 0;

Jquery Dollar sign Uncaught

  1. jQuery(document).ready(function($){
  2. // Script Here
  3. });

Scroll to Nav Menu Fixed

  1. // Scroll to fixed menu
  2. jQuery(document).ready(function($){
  3. // Create a clone of the menu, right next to original.
  4. $('.parent_menu').addClass('original').clone().insertAfter('.parent_menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();
  5. scrollIntervalID = setInterval(stickIt, 10);
  6. function stickIt() {
  7. var orgElementPos = $('.original').offset();
  8. orgElementTop = orgElementPos.top;
  9. if ($(window).scrollTop() >= (orgElementTop)) {
  10. // scrolled past the original position; now only show the cloned, sticky element.
  11. // Cloned element should always have same left position and width as original element.
  12. orgElement = $('.original');
  13. coordsOrgElement = orgElement.offset();
  14. leftOrgElement = coordsOrgElement.left;
  15. widthOrgElement = orgElement.css('width');
  16. $('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show();
  17. $('.original').css('visibility','hidden');
  18. } else {
  19. // not scrolled past the menu; only show the original menu.
  20. $('.cloned').hide();
  21. $('.original').css('visibility','visible');
  22. }
  23. }
  24. });

Placeholder CSS

  1. input::placeholder {
  2. color: white !important;
  3. opacity:1;
  4. }
  5. input::-webkit-input-placeholder {
  6. color: white !important;
  7. opacity:1;
  8. }
  9. input:-moz-placeholder {
  10. color: white !important;
  11. opacity:1;
  12. }
  13. input::-moz-placeholder {
  14. color: white !important;
  15. opacity:1;
  16. }
  17. input::-ms-input-placeholder {
  18. color: white !important;
  19. opacity:1;
  20. }
  21. input::-ms-input-placeholder {
  22. color: white !important;
  23. opacity:1;
  24. }

CF7 Validation CSS

  1. .wpcf7-form-control.input.wpcf7-not-valid {
  2. border: 1px solid #ff0000 !important;
  3. }
  4. .wpcf7-form .wpcf7-response-output.wpcf7-validation-errors {
  5. color: #D8000C;
  6. background-color: #FFBABA;
  7. border: 0;
  8. padding: 2px;
  9. text-align: left;
  10. width: 100%;
  11. }
  12. span.wpcf7-not-valid-tip {
  13. color: #D8000C;
  14. background-color: #FFBABA;
  15. text-align: left;
  16. border: 0;
  17. padding: 2px;
  18. width: 100%;
  19. margin-bottom: -34px;
  20. margin-top: 4px;
  21. }
  22. .wpcf7-form .wpcf7-response-output.wpcf7-mail-sent-ok {
  23. color: #4F8A10;
  24. background-color: #DFF2BF;
  25. border: 0;
  26. padding: 2px;
  27. text-align: left;
  28. width: 100%;
  29. }
  30. div.wpcf7-mail-sent-ok:before,div.wpcf7-validation-errors:before,span.wpcf7-not-valid-tip:before {
  31. font: 26px/30px dashicons;
  32. margin-right: 16px;
  33. vertical-align: middle;
  34. }
  35. /* Dashicons Icon */
  36. div.wpcf7-mail-sent-ok:before {
  37. content: "\f147";
  38. }
  39. div.wpcf7-validation-errors:before,span.wpcf7-not-valid-tip:before {
  40. content: "\f158";
  41. }
  42. /* Font-Awesome Icon */
  43. div.wpcf7-mail-sent-ok:before {
  44. content:'\f00c';
  45. }
  46. div.wpcf7-validation-errors:before, span.wpcf7-not-valid-tip:before {
  47. content:'\f057';
  48. }

Woocomerce Email Validation

  1. // Woocomerce Checkout Email Validation
  2. add_action('woocommerce_checkout_process', 'checkout_email_valid');
  3. function checkout_email_valid() {
  4.     $email = checkout_input_sanitize($_POST["billing_m"]);
  5.     $email2 = checkout_input_sanitize($_POST["billing_m2"]);
  6.     // check if botm e-mail address is filled
  7. if($email !== $email2) {
  8.             wc_add_notice( __( 'Both email address need to be same.' ), 'error' );
  9. }
  10. // check if e-mail address is well-formed
  11.     if(!filter_var($email, FILTER_VALIDATE_EMAIL) || !filter_var($email2, FILTER_VALIDATE_EMAIL)) {
  12.     wc_add_notice( __( 'Email Address is not valid.' ), 'error' );
  13. }
  14. }
  15. // Woocomerce Checkout Input Sanitize
  16. function checkout_input_sanitize($data) {
  17. $data = trim($data);
  18. $data = stripslashes($data);
  19. $data = htmlspecialchars($data);
  20. return $data;
  21. }