Skip to content

Instantly share code, notes, and snippets.

@JasvinderSingh1
Last active February 21, 2021 18:37
Show Gist options
  • Save JasvinderSingh1/b91fae78aa953eee2bbe3aaefa604c94 to your computer and use it in GitHub Desktop.
Save JasvinderSingh1/b91fae78aa953eee2bbe3aaefa604c94 to your computer and use it in GitHub Desktop.
WORDPRESS CODES
// reference for Wordpress Functions
https://codex.wordpress.org/Function_Reference
https://developer.wordpress.org/
/***********************/
Display terms with pagination start
if ( get_query_var( 'paged' ) )
$paged = get_query_var('paged');
else if ( get_query_var( 'page' ) )
$paged = get_query_var( 'page' );
else
$paged = 1;
$per_page = 4;
$number_of_series = count( get_terms( 'product_cat',array('hide_empty'=>'0') ) );
$offset = $per_page * ( $paged - 1) ;
// Setup the arguments to pass in
$args = array(
'offset' => $offset,
'number' => $per_page,
'hide_empty'=>'0'
);
// Gather the series
$product_cat = get_terms( 'product_cat', $args );
// Loop through and display the series
foreach($product_cat as $s)
{
$theurl = get_term_link($s, 'product_cat');
echo '<div class="ser-img img" ><a href="'. $theurl . '">'. $s->name .'</a></div><br /><br />';
}
echo '<br />';
$big = 999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $paged,
'total' => ceil( $number_of_series / $per_page ) // 3 items per page
) );
Display terms with pagination end
/************************/
// filter to remove http error on file upload in wordpress
add_filter( 'wp_image_editors', 'change_graphic_lib' );
function change_graphic_lib($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
#to remove links atc
pointer-events: none;
//---- to display features product slider --//
[featured_products_slider]
//---- for media css --//
@media (min-width:200px) and (max-width: 479px) {
.home .project-short-desc{
font-size:11px;
padding:0 15px 10px;
}}
@media only screen
and (min-width : 768px)
and (max-width : 1024px) {
li.Request-a-Callback-custom a {font-size:21px !important;}
}
//---- Enable all HTML Tags in Profile Bios--//
To disable the default WordPress HTML tag “sanitization”, you can add this snippet to your theme’s functions.php file or in your own separate plugin:
//disable WordPress sanitization to allow more than just $allowedtags from /wp-includes/kses.php
remove_filter('pre_user_description', 'wp_filter_kses');
//add sanitization for WordPress posts
add_filter( 'pre_user_description', 'wp_filter_post_kses');
Warning
WordPress sanitizes user input for security reasons, not just to annoy you and make you go on a hunt to find this post to learn how to override the annoying setting.
If you’re considering disabling the WordPress sanitization, make sure you trust your users to not enter potentially harmful content into their profile bios. This includes iframes, forms, and more.
Disable all HTML in Profile Bios
If you want the opposite, disallowing all HTML (including the a, blockquote, em, and strong tags, to name a few), you can use the following snippet:
1
2 //disallow all HTML tags
add_filter( 'pre_user_description', 'wp_filter_nohtml_kses');
//how to change host in window 32 file
1. Press the Windows key.
2. Type Notepad in the search field.
3. In the search results, right-click Notepad and select Run as administrator.
4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts.
5. Make the necessary changes to the file.
6. Click File > Save to save your changes.
/// how to print array data in php
print_r();
////How to Add Mailchimp Signup Form at the end of every post
Add form to all posts automatically
Adding a MailChimp for WordPress sign-up form to the end of all singular posts is easy. Just add the following snippet your theme its functions.php file, for example.
You can find this file in the following location: /wp-content/themes/your-theme/functions.php
Please make sure to change the $form_id variable to the actual ID of the form you would like to show. If you omit this line, your default form will be showed.
/**
* Adds a form to the end of all single posts
*
* @param string $content
*
* @return string $content
*/
function myprefix_add_form_to_posts( $content ) {
// Change to ID of the form you want to add
$form_id = 0;
// Check if this is a single post.
if ( is_singular( 'post' ) ) {
// Add the form to the end of the post content.
$content .= mc4wp_get_form( $form_id );
}
// Returns the content.
return $content;
}
add_filter( 'the_content', 'myprefix_add_form_to_posts' );
// to display self made sidebars
dynamic_sidebar( 'left-sidebar' );
// how to display custom/non-custom widget in avada
<?php if (!dynamic_sidebar('avada-custom-sidebar-name')) : ?>
<?php dynamic_sidebar('avada-custom-sidebar-name'); ?>
<?php endif; ?>
//how to increase maximum upload size using .user.ini
Changing Your Max Upload
upload_max_filesize = 1000M
Ref: https://kb.site5.com/php/how-to-make-custom-php-changes-using-a-user-ini-file
//How do I use a php echo inside a short code in Wordpress?
<?php echo do_shortcode('[wpaft_logo_slider]'); ?>
// HOW TO ADD button for previous and next post after a post in wordpress?
<div style="width:100%">
<div class="buttons" style="width:50%; float:left;"><span class="previous-button"><?php previous_post_link('%link', '&laquo;&laquo; Previous Post'); ?></span></div>
<div class="buttons" style="width:50%; float:left; text-align:right;"><span class="next-button"><?php next_post_link('%link', 'Next Post &raquo;&raquo;'); ?></span></div>
</div>
//how to crop length of text using css
#div2 {
white-space: nowrap;
width: 5em;
overflow: hidden;
text-overflow: ellipsis;
}
//Limit text length to n lines using CSS
.text {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
line-height: 16px; /* fallback */
max-height: 48px; /* fallback */
-webkit-line-clamp: 3; /* number of lines to show */
-webkit-box-orient: vertical;
}
//How to display post categories with images in a grid layout in custom wordpress template
First activate Category Image Plugin
<?php foreach (get_categories() as $cat) : ?>
<div class="fusion-one-third fusion-layout-column fusion-spacing-yes">
<a href="<?php echo get_category_link($cat->term_id); ?>">
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<?php echo $cat->cat_name; ?>
</a>
</div>
<?php endforeach; ?>
** https://stackoverflow.com/questions/44132290/how-to-display-post-category-with-image-in-grid-layout-in-wordpress
//How to display featured pages with images in a grid layout in custom wordpress template using “NS Featured Posts” Plugin by Nilamber Sharma
(https://wordpress.org/plugins/ns-featured-posts/)
<?php
$mypages = get_pages( array(
'sort_order' => 'asc',
'meta_key' => '_is_ns_featured_post',
'meta_value' => 'yes'
) );
$limit=3;
$counter=0;
foreach( $mypages as $page ) {
if($counter<$limit){
$content = $page->post_content;
$content = apply_filters( 'the_content', $content );
?>
<div class="fusion-one-third fusion-layout-column fusion-spacing-yes">
<a href="<?php echo get_page_link( $page->ID ); ?>">
<?php echo get_the_post_thumbnail($page->ID); ?>
<h1 class="customp pagep"><?php echo $page->post_title; ?></h1>
</a>
</div>
<?php $counter++;
} } ?>
//to display year using script
<script>document.write(new Date().getFullYear());</script>
// how to display current user(logged in user) info and custom fields of users in frontend
Plugins used: Advanced Custom Field
Wp user manager By Alessandro Tesoro
<?php global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User level: ' . $current_user->user_level . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";
?>
<?php $user_ID = get_current_user_id();
$number = 'user_' . $user_ID;
the_field('project', $number); ?> <br/>
/**
* Change currency display in WooCommerce
* Put this in your functions.php file
*
*/
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'EUR': $currency_symbol = 'Eur '; break;
}
return $currency_symbol;
}
// how to add custom font in wordpress
In style.css, write this:
@font-face {
font-family: agenda-light;
src: url(http://movehappy.co.uk/wp-content/themes/houzez-child/fonts/agenda-light.otf);
}
Then in custom.css; use
body{font-family: agenda-light !important;}
//Selecting first td in the first table with CSS 3
#container table:first-child tr:first-child td:first-child { background: red; }
//Using CSS how to change only the 2nd column of a table
.custom-table table tr td:nth-child(2) { text-align:center !important;padding-left:0px !important; }
// custom post order using drag and drop method
Plugin Intuitive Custom Post Order By hijiri
// how to make function.php in child theme
Write
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
// adding custom style and scripts in wordpress
function add_theme_scripts() {
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slideraaa.css', array(), '1.1', 'all');
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
//ikkurty
window.onload = function()
{
if ( jQuery(window).width() > 1280) {
document.getElementById('sliders-container').className = 'transition2';
}
else if ( jQuery(window).width() > 600 && jQuery(window).width() < 1280) {
document.getElementById('sliders-container').className = 'transition3';
}
else if ( jQuery(window).width() < 600) {
document.getElementById('sliders-container').className = 'transition4';
}
var size = -500;
var elems = document.getElementsByClassName('transition2');
for(var i = 0; i < elems.length; i++) {
elems[i].style.marginTop = size + "px";
}
var size = -360;
var elems = document.getElementsByClassName('transition3');
for(var i = 0; i < elems.length; i++) {
elems[i].style.marginTop = size + "px";
}
var size = -200;
var elems = document.getElementsByClassName('transition4');
for(var i = 0; i < elems.length; i++) {
elems[i].style.marginTop = size + "px";
}
};
// how to leverage browser caching
Write this code in .htaccess
# FileETag None is not enough for every server.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
# Since we’re sending far-future expires, we don’t need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None
# Expires headers (for better cache control)
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Feed
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType application/x-font-woff2 "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
A Better Method for Embedding YouTube Videos on your Website
https://www.labnol.org/internet/light-youtube-embeds/27941/
<div class="youtube-player" data-id="VIDEO_ID"></div>
Next, place the JavaScript anywhere in your web template. It finds all embedded videos on a web page and then replaces the DIV elements with the video thumbnails.
<script>
/* Light YouTube Embeds by @labnol */
/* Web: http://labnol.org/?p=27941 */
document.addEventListener("DOMContentLoaded",
function() {
var div, n,
v = document.getElementsByClassName("youtube-player");
for (n = 0; n < v.length; n++) {
div = document.createElement("div");
div.setAttribute("data-id", v[n].dataset.id);
div.innerHTML = YouTubeThumb(v[n].dataset.id);
div.onclick = YouTubeIframe;
v[n].appendChild(div);
}
});
function YouTubeThumb(id) {
var thumb = '<img src="https://i.ytimg.com/vi/ID/hqdefault.jpg">',
play = '<div class="play"></div>';
return thumb.replace("ID", id) + play;
}
function YouTubeIframe() {
var iframe = document.createElement("iframe");
var embed = "https://www.youtube.com/embed/ID?autoplay=1";
iframe.setAttribute("src", embed.replace("ID", this.dataset.id));
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("allowfullscreen", "1");
this.parentNode.replaceChild(iframe, this);
}
</script>
Finally, paste the CSS before the closing head tag of your web template.
<style>
.youtube-player {
position: relative;
padding-bottom: 56.23%;
/* Use 75% for 4:3 videos */
height: 0;
overflow: hidden;
max-width: 100%;
background: #000;
margin: 5px;
}
.youtube-player iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
background: transparent;
}
.youtube-player img {
bottom: 0;
display: block;
left: 0;
margin: auto;
max-width: 100%;
width: 100%;
position: absolute;
right: 0;
top: 0;
border: none;
height: auto;
cursor: pointer;
-webkit-transition: .4s all;
-moz-transition: .4s all;
transition: .4s all;
}
.youtube-player img:hover {
-webkit-filter: brightness(75%);
}
.youtube-player .play {
height: 72px;
width: 72px;
left: 50%;
top: 50%;
margin-left: -36px;
margin-top: -36px;
position: absolute;
background: url("//i.imgur.com/TxzC70f.png") no-repeat;
cursor: pointer;
}
</style>
http://tubularinsights.com/download-youtube-thumbnail-images-creators-tip-120/
Small custom thumbnail
http://img.youtube.com/vi/VIDEOID/mqdefault.jpg
Medium custom thumbnail at 4:3 ratio
http://img.youtube.com/vi/VIDEOID/0.jpg
Large custom thumbnail
http://img.youtube.com/vi/VIDEOID/maxresdefault.jpg (only available if video has 720p or 1080p option)
// cache control in .htaccess
Put below code in .htaccess
# FileETag None is not enough for every server.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
# Since we’re sending far-future expires, we don’t need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None
# Expires headers (for better cache control)
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Feed
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType application/x-font-woff2 "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
A better method to embed Google map in wordpress to increase page speed
https://firstsiteguide.com/speed-site-properly-including-google-maps/
<div id="my-fast-map" data-iframe-width="600" data-iframe-height="300" data-iframe-src="IFRAME-URL">
<a href="#" title="Click to activate map"><img src="IMAGE-URL-YOU-COPIED” alt="Click to activate map"></a>
</div>
# for Image source https://staticmapmaker.com/google/
#jquery
jQuery(function($) {
$('#my-fast-map a').on('click', function(e) {
e.preventDefault();
map = $(this).parent();
iframe_src = map.data('iframe-src');
iframe_width = map.data('iframe-width');
iframe_height = map.data('iframe-height');
map.html('<iframe src="' + iframe_src + '" width="' + iframe_width + '" height="' + iframe_height + '" allowfullscreen></iframe>');
return false;
});
});
#CSS
#my-fast-map img {
border: none;
padding: 10px;
}
#my-fast-map iframe {
border: none;
}
//Best Way to Defer Parsing of JavaScript in WordPress
Write this code in function.php
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
// registering custom post type and custom meta
Src: https://wptheming.com/2010/08/custom-metabox-for-post-type/
/**
* Registers the event post type.
*/
function wpt_event_post_type() {
$labels = array(
'name' => __( 'Events' ),
'singular_name' => __( 'Event' ),
'add_new' => __( 'Add New Event' ),
'add_new_item' => __( 'Add New Event' ),
'edit_item' => __( 'Edit Event' ),
'new_item' => __( 'Add New Event' ),
'view_item' => __( 'View Event' ),
'search_items' => __( 'Search Event' ),
'not_found' => __( 'No events found' ),
'not_found_in_trash' => __( 'No events found in trash' )
);
$supports = array(
'title',
'editor',
'thumbnail',
'comments',
'revisions',
);
$args = array(
'labels' => $labels,
'supports' => $supports,
'public' => true,
'capability_type' => 'post',
'rewrite' => array( 'slug' => 'events' ),
'has_archive' => true,
'menu_position' => 30,
'menu_icon' => 'dashicons-calendar-alt',
'register_meta_box_cb' => 'wpt_add_event_metaboxes',
);
register_post_type( 'events', $args );
}
add_action( 'init', 'wpt_event_post_type' );
/**
* Adds a metabox to the right side of the screen under the “Publish” box
*/
function wpt_add_event_metaboxes() {
add_meta_box(
'wpt_events_location',
'Event Location',
'wpt_events_location',
'events',
'side',
'default'
);
}
/**
* Output the HTML for the metabox.
*/
function wpt_events_location() {
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'event_fields' );
// Get the location data if it's already been entered
$location = get_post_meta( $post->ID, 'location', true );
// Output the field
echo '<input type="text" name="location" value="' . esc_textarea( $location ) . '" class="widefat">';
}
/**
* Save the metabox data
*/
function wpt_save_events_meta( $post_id, $post ) {
// Return if the user doesn't have edit permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times.
if ( ! isset( $_POST['location'] ) || ! wp_verify_nonce( $_POST['event_fields'], basename(__FILE__) ) ) {
return $post_id;
}
// Now that we're authenticated, time to save the data.
// This sanitizes the data from the field and saves it into an array $events_meta.
$events_meta['location'] = esc_textarea( $_POST['location'] );
// Cycle through the $events_meta array.
// Note, in this example we just have one item, but this is helpful if you have multiple.
foreach ( $events_meta as $key => $value ) :
// Don't store custom data twice
if ( 'revision' === $post->post_type ) {
return;
}
if ( get_post_meta( $post_id, $key, false ) ) {
// If the custom field already has a value, update it.
update_post_meta( $post_id, $key, $value );
} else {
// If the custom field doesn't have a value, add it.
add_post_meta( $post_id, $key, $value);
}
if ( ! $value ) {
// Delete the meta key if there's no value
delete_post_meta( $post_id, $key );
}
endforeach;
}
add_action( 'save_post', 'wpt_save_events_meta', 1, 2 );
// how to Create an auto-complete field in WordPress
https://davidnash.com.au/create-an-auto-complete-field-in-wordpress/
// how to read QR codeusing rear camera
https://github.com/gruhn/vue-qrcode-reader
//Make WooCommerce pages accessible for logged in users only
function wpse_131562_redirect() {
if (
! is_user_logged_in()
&& (is_woocommerce() || is_cart() || is_checkout())
) {
// feel free to customize the following line to suit your needs
wp_redirect(home_url());
exit;
}
}
add_action('template_redirect', 'wpse_131562_redirect');
//Show Additional Content on the WooCommerce My Account Page
/**
* @snippet Show Additional Content on the My Account Page
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=19113
* @author Rodolfo Melogli (improved by Tom Lambie)
* @compatible WooCommerce 3.3.4
*/
add_action( 'woocommerce_login_form_start','bbloomer_add_login_text' );
function bbloomer_add_login_text() {
echo '<h3 class="bb-login-subtitle">Registered Customers</h3><p class="bb-login-description">If you have an account with us, log in using your email address.</p>';
}
add_action( 'woocommerce_register_form_start','bbloomer_add_reg_text' );
function bbloomer_add_reg_text() {
echo '<h3 class="bb-register-subtitle">New Customers</h3><p class="bb-register-description">By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.</p>';
}
Turn Add to Cart “Quantity” into a select drop-down – WooCommerce
https://businessbloomer.com/woocommerce-change-add-cart-quantity-drop/
/**
* @snippet Add to Cart Quantity drop-down - WooCommerce
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=72757
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.1.1
*/
function woocommerce_quantity_input() {
$min = 1;
$max = 5;
$step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$options .= '<option value="' . $count . '">' . $count . '</option>';
}
echo '<div class="select-qty"><label>Qty</label><select name="quantity">' . $options . '</select></div>';
}
/*
* enqueing scripts
*/
add_action( 'admin_enqueue_scripts', array( $this, 'church_survey_admin_enqueue_scripts' ) );
}
function church_survey_admin_enqueue_scripts(){
wp_enqueue_script( 'highchart3', 'https://code.highcharts.com/modules/export-data.js', array ( 'jquery' ), 1.1, true);
}
Plugin to add social media in any menu | Menu Image by Alex Davyskiba aka Zviryatko
Subscribe popup| wp subscribe pro
Navigation in one page | One page navigator (add on of visual composer)
Custom Post Type UI | Custom Post Type UI provides an easy to use interface for registering and managing custom post types and taxonomies for your website.
Popup Plugin for WordPress - Layered Popups
Best plugin for pop up
https://codecanyon.net/item/layered-popups-for-wordpress/5978263
// operlog problem
<p class="price"><?php
if($product->get_price() == '')
{
?>
<?php //echo do_shortcode('[AnythingPopup id="1"]');
echo $product->get_sku();
echo "<br/>";
echo 'Out of Stock';
echo "<br>";
echo '<span class="wc_email_inquiry_button_container"><a class="wc_email_inquiry_email_button wc_email_inquiry_button_'.$product->get_id().' wc_email_inquiry_popup_button wc_email_inquiry_button_closed " id="wc_email_inquiry_button_'.$product->get_id().'" product_name="'.$product->get_name().'" product_id="'.$product->get_id().'" form_action="hide">Ask For Quote</a></span>';
?>
<?php
}
//echo $product->get_price_html();
else {
echo $product->get_sku();
echo "<br/>";
echo 'In Stock';
echo "<br>";
echo '<span class="wc_email_inquiry_button_container"><a class="wc_email_inquiry_email_button wc_email_inquiry_button_'.$product->get_id().' wc_email_inquiry_popup_button wc_email_inquiry_button_closed " id="wc_email_inquiry_button_'.$product->get_id().'" product_name="'.$product->get_name().'" product_id="'.$product->get_id().'" form_action="hide">Ask For Quote</a></span>';
}
?></p>
//my extraordinary blog
To display categories and their images in custom template
http://www.myextraordinary.blog/
<?php
$categories = get_categories( array(
'hide_empty' => 0,
'parent' => 0
) );
$limit=6;
$counter=0;
foreach ($categories as $cat) :
if($cat->term_id != '1') {
if($counter<$limit){
?>
<div class="fusion-one-third fusion-layout-column fusion-spacing-yes">
<a href="<?php echo get_category_link($cat->term_id); ?>">
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<h1 class="customp"><?php echo $cat->cat_name; ?></h1>
</a>
</div>
<?php $counter++;
}}
endforeach; ?>
// to display only featured pages with their featured images in custom template
http://www.myextraordinary.blog/
Plugin: https://wordpress.org/plugins/ns-featured-posts/
<?php
$mypages = get_pages( array(
'sort_order' => 'asc',
'meta_key' => '_is_ns_featured_post',
'meta_value' => 'yes'
) );
$limit=3;
$counter=0;
foreach( $mypages as $page ) {
if($counter<$limit){
$content = $page->post_content;
$content = apply_filters( 'the_content', $content );
?>
<div class="fusion-one-third fusion-layout-column fusion-spacing-yes">
<a href="<?php echo get_page_link( $page->ID ); ?>">
<?php echo get_the_post_thumbnail($page->ID); ?>
<h1 class="customp"><?php echo $page->post_title; ?></h1>
</a>
</div>
<?php $counter++;
} } ?>
//how to validate 20 (multiple) emails with jquery
Plugin used to input javascript: https://wordpress.org/plugins/custom-css-js/
http://avvery.org
jQuery(function($) {
$('#pmpro_paypalexpress_checkout').click(function() {
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
for(i=1;i<=20;i++)
{
var emailList= $("#countMe"+i+"").val();
if(emailList == '') {
$("#countMe"+i+"").after('<span class="error">Please enter your email address.</span>');
hasError = true;
}
else{
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(emailList))
{
//var limitemail = emailList;
$("#countMe"+i+"").after('<span class="error">Enter a valid email address.</span>');
hasError = true;
}
}
if(hasError == true) { return false; }
}
});
});
//How to validate and input multiple emails in one input box using javascript
Plugin used to input javascript: https://wordpress.org/plugins/custom-css-js/
jQuery(function($) {
$('#pmpro_paypalexpress_checkout').click(function() {
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var emailList= $("#countMe").val().split(',');
if(emailList == '') {
$("#countMe").after('<span class="error">Please enter your 20 emails address by comma seperated.</span>');
hasError = true;
}
for (i=0;i<emailList.length;i++)
{
if(i != 20)
{
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(emailList[i]))
{
var limit = i+1;
var limitemail = emailList[i];
$("#countMe").after('<span class="error">Enter a valid ' + limitemail + ' email address.</span>');
hasError = true;
}
}
else
{
$("#countMe").after('<span class="error">only 20 allowed.</span>');
hasError = true;
}
}
if(hasError == true) { return false; }
});
});
//How to add content before using Wordpress hook (filter)
<?php
function theme_slug_filter_the_content( $content ) {
$custom_content = 'YOUR CONTENT GOES HERE';
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );
?>
//How to add content after using Wordpress hook (filter)
<?php
function theme_slug_filter_the_title( $title ) {
$custom_title = 'YOUR CONTENT GOES HERE';
$title .= $custom_title;
return $title;
}
add_filter( 'the_title', 'theme_slug_filter_the_title' );
?>
//Returning shortcode using Hook/ filter in wordpress
function property_slideshow( $content ) {
if ( is_single() && 'property' == get_post_type() ) {
$custom_content = '[portfolio_slideshow]';
$custom_content .= $content;
return $custom_content;
} else {
return $content;
}
}
add_filter( 'the_content', 'property_slideshow' );
A list of Font Awesome icons and their CSS content values
http://astronautweb.co/snippet/font-awesome/
//Enable gzip using htaccess
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
// using admin ajax in WP
// Put it in js file and enque the file
jQuery.ajax({
url : '/wp-admin/admin-ajax.php',
type : 'post',
data : {
action : 'getdetails',
listing_id : 50
},
success : function( response ) {
console.log( response );
var obj = jQuery.parseJSON(response);
$('#fixed').raty('set', { score : obj.abc, readOnly: true });
}
});
// Put it in function.php
add_action( 'wp_ajax_nopriv_getdetails', 'getdetails' );
add_action( 'wp_ajax_getdetails', 'getdetails' );
function getdetails(){
$compare_id = $_POST['listing_id'];
$result['abc'] = get_field('grillenpicknick', $compare_id);
$result['qwe'] = 25;
$results = wp_json_encode($result);
echo $results; die;
}
//display custom posts with pagination
$the_query = new WP_Query( array('posts_per_page'=>2,
'post_type'=>'post',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
);
?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="col-xs-12 file">
<a href="<?php the_permalink(); ?>" class="file-title" target="_blank">
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php echo get_the_title(); ?>
</a>
<div class="file-description"><?php the_content(); ?></div>
</div>
<?php
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_postdata();
// wp_query
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'category' => $kategory,
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true,
'fields' => '',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'altersempfehlung',
'value' => $field_1,
'compare' => 'LIKE',
),
array(
'key' => 'bezirk',
'value' => $field_2,
'compare' => 'LIKE',
),
),
'date_query' => array( 'after' => $search_date ),
);
// The Query
$query = new WP_Query( $args );
Slick slider js demo
https://codepen.io/vilcu/pen/ZQwdGQ
Add new coloumn in product listing in admin panel
/*
* Start:Add custom column on post grid
*/
//filter grid column
add_action( 'manage_edit-product_columns', 'my_custom_edit_movie_columns');
function my_custom_edit_movie_columns($columns) {
$columns['product_type'] = __( 'Type' );
return $columns;
}
// add custom column valuse
add_action( 'manage_product_posts_custom_column', 'my_custom_activity_columns', 10, 2);
function my_custom_activity_columns( $column, $post_id ) {
switch( $column )
{
case 'product_type' :
echo get_post_meta($post_id,'product_type',true);
break;
default :
break;
}
}
/*
* End:Add custom column on post grid
*/
// uploading a repository in git
https://www.tutsmake.com/upload-project-files-on-github-using-command-line/
@humbertorames
Copy link

this is exactly what I was looking for
thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment