Skip to content

Instantly share code, notes, and snippets.

@rahuladams
rahuladams / Custom Post Type UI - Display in theme.
Created June 19, 2020 12:40
How to display Custom Post Type UI content in the theme.
<?php
$args = array(
'post_type' => 'cptui_post_slug',
'posts_per_page' => 10,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'paged' => $paged,
);
$post_name = new WP_Query( $args );
//Add Custom Style
add_action('wp_enqueue_scripts','custom_child_styles_scripts',999);
function custom_child_styles_scripts()
{
wp_enqueue_style('custom-css',get_stylesheet_directory_uri().'/dist/custom.css',array(),'1.0.0',false);
}
//Removed unwanted menus
// Get featured image
<?php get_the_post_thumbnail_url(); ?>
// Content loop
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
// Breadcrumbs
function get_breadcrumb() {
echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
if (is_category() || is_single()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
the_category(' &bull; ');
if (is_single()) {
echo " &nbsp;&nbsp;&#187;&nbsp;&nbsp; ";
the_title();
}
var accordion_items = document.querySelectorAll('.accordion-item');
if (accordion_items != null) {
var i = 0;
accordion_items.forEach(function (e) {
i++;
e.addEventListener('click', function () {
e.querySelector('.accordion-content').classList.toggle('active');
});
})
}
add_action( 'woocommerce_before_checkout_form', 'custom_apply_matched_coupons' );
add_action( 'woocommerce_before_cart', 'custom_apply_matched_coupons' );
function custom_apply_matched_coupons() {
$coupon_code = 'coupon_code_here';
$cat_in_cart = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( has_term( 'product-category-slug', 'product_cat', $cart_item['product_id'] ) ) {
function getVisIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
//HTML
<div id="burger">
<button class="hamburger hamburger--elastic ripple" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
@rahuladams
rahuladams / Register Wordpress Menu
Created June 12, 2020 12:22
How to register a new menu in dashboard and use it in the theme
//in functions
function register_my_menus() {
register_nav_menus(
array(
'new-menu' => __( 'New Menu' ),
'another-menu' => __( 'Another Menu' ),
'an-extra-menu' => __( 'An Extra Menu' )
)
);
}
@rahuladams
rahuladams / Nginx - CORS fix for fonts
Created May 27, 2020 08:47
Add this to the server block config file.
location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}