Category: WordPress

How to Enqueue Google Fonts on WordPress Theme

Register custom fonts

/**
 * Register custom fonts.
 */
function themeslug_fonts_url() {
	$fonts_url = '';
	$fonts     = array();
	$subsets   = 'latin,latin-ext';

	/*
	 * Translators: If there are characters in your language that are not supported
	 * by Oswald, translate this to 'off'. Do not translate into your own language.
	 */
	if ( 'off' !== _x( 'on', 'Oswald font: on or off', 'themeslug' ) ) {
		$fonts[] = 'Oswald:400,700';
	}

	/*
	 * Translators: If there are characters in your language that are not supported
	 * by Montserrat, translate this to 'off'. Do not translate into your own language.
	 */
	if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'themeslug' ) ) {
		$fonts[] = 'Montserrat:400,700';
	}


	if ( $fonts ) {
		$fonts_url = add_query_arg( array(
			'family' => urlencode( implode( '|', $fonts ) ),
			'subset' => urlencode( $subsets ),
		), 'https://fonts.googleapis.com/css' );
	}


	return esc_url_raw( $fonts_url );
}

Continue Reading

How to display WordPress post view count without a plugin

Tutorial 1

Use this code in functions.php

function rm_post_view_count(){
	if ( is_single() ){
		global $post;
		$count_post = esc_attr( get_post_meta( $post->ID, '_post_views_count', true) );
		if( $count_post == ''){
			$count_post = 1;
			add_post_meta( $post->ID, '_post_views_count', $count_post);
		}else{
			$count_post = (int)$count_post + 1;
			update_post_meta( $post->ID, '_post_views_count', $count_post);
		}
	}
}
add_action('wp_head', 'rm_post_view_count');

Continue Reading

Visual Composer Get images from “attach_images”

In VC_MAP definition you have:

array(
	"type"        => "attach_images",
	"heading"     => esc_html__( "Screenshots", "text-domain" ),
	"description" => esc_html__( "Add screenshots.", "text-domain" ),
	"param_name"  => "screenshots",
	"value"       => "",
),

In shortcode function you should have: Continue Reading

Custom Post Pagination not working

Custom post query

  1. post type download
  2. post content style content-item.php
  3. post pagination function st_posts_pagination
 <?php
 global $wp_query;
 query_posts( array('post_type' => array( 'download' ), 'paged'=>$paged )
 );?>

 <?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
 <?php get_template_part('content', 'item'); ?>
 <?php endwhile; ?>
 <?php ?>
 <div class="col-md-12">
 <div class="page-link text-center">
 <?php st_posts_pagination(); ?>
 </div>
 </div>

 <?php endif; ?>

Continue Reading