Skip to content

Instantly share code, notes, and snippets.

View yuriitaran's full-sized avatar

Yurii Taran yuriitaran

View GitHub Profile
// Show post type Singular Label on singular post page:
$post = get_queried_object();
$postType = get_post_type_object(get_post_type($post));
if ($postType) {
echo esc_html($postType->labels->singular_name);
}
// Show post type Singular Label in the loop:
$postType = get_post_type_object(get_post_type());
if ($postType) {
<?php
$menu_location = 'main-menu';
$menu_locations = get_nav_menu_locations();
$menu_object = (isset($menu_locations[$menu_location]) ? wp_get_nav_menu_object($menu_locations[$menu_location]) : null);
$menu_name = (isset($menu_object->name) ? $menu_object->name : '');
echo esc_html($menu_name);
?>
@yuriitaran
yuriitaran / WP_Query to display content from custom post type object
Created October 24, 2017 19:45
WP_Query to display content from custom post type object
<?php $the_query = new WP_Query( array( 'post_type' => 'slider', 'order' => 'ASC' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<img src="<?php the_field('slide_image'); ?>" alt="<?php the_field('slide_title'); ?>" />
<?php the_field('slide_title'); ?>
<?php endwhile; ?>
@yuriitaran
yuriitaran / Link to WP post
Created October 24, 2017 20:54
A stupid reminder
<?php echo esc_url( get_permalink( $post ) ); ?>
@yuriitaran
yuriitaran / WP shortcode with variable
Last active October 24, 2017 22:58
WP shortcode with variable
<?php echo do_shortcode('['.get_field('custom_field_name').']'); ?>
<?php $the_query = new WP_Query( array( 'post_type' => 'post', 'order' => 'ASC' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'template-parts/page/content', 'front-page' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
@yuriitaran
yuriitaran / WP: Sample shortcode with parameters
Last active April 19, 2018 11:00
Sample shortcode with parameters
// More info: https://speckyboy.com/getting-started-with-wordpress-shortcodes-examples/
function sample_template($title, $type, $order) {
$the_query = new WP_Query( array( 'post_type' => $type, 'order' => $order, ) );
if ( $the_query->have_posts() ) : ?>
<h2><?php echo $title; ?></h2>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<p>
@yuriitaran
yuriitaran / WP Theme Options
Last active November 7, 2017 12:37
WP Theme Options
/**
* Theme Options
*/
add_action('customize_register', function($wp_customize) {
/**
* Add Custom Logo
*/
$wp_customize->add_setting('logo_img');
@yuriitaran
yuriitaran / jQuery: Outline 'none' for all links on mouse click
Last active February 10, 2018 12:41
Outline 'none' for all links on mouse click
@yuriitaran
yuriitaran / JQuery scroll to specific position
Last active November 7, 2017 12:37
JQuery scroll to specific position
$('html, body').animate({
scrollTop: ($('.sroll-to-element').first().offset().top)
},500);
// Scroll to Main content
$( '.scroll-to-content' ).click(function() {
$('html, body').animate({
scrollTop: ($('.homepage-main').first().offset().top)
},800);
});