CodeHQ

Posts Tagged ‘PHP’

| Newer Entries »

Adding SVG support to WordPress

Friday, May 20th, 2016

Add to functions.php

function cc_mime_types( $mimes ){
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );

Tags: , , ,
Posted in PHP, WordPress | No Comments »

Hiding empty fields with ACF | WordPress

Tuesday, March 8th, 2016

<?php if( get_field('video_url') ):?>
	Show this if field exists <?php the_field('video_url');?>
<?php else : ?>
    Show this if not
<?php endif;?>			

Tags: , , ,
Posted in PHP, WordPress | No Comments »

Sidebar.php WordPress template for dynamic sidebars | PHP

Tuesday, January 19th, 2016

This code can be added in to sidebar.php or any other theme file.

<?php if ( is_active_sidebar( 'sidebar_name' ) ) : 
    dynamic_sidebar( 'sidebar_name' );
endif; ?>

Tags: , , ,
Posted in PHP, WordPress | No Comments »

Show current year with PHP (copyright)

Wednesday, January 6th, 2016

Add this code to your website to show the current year e.g. 2016. Can be used to always show the current year in the date format in a copyright statement.

<?php echo date("Y") ?>

Tags: , , , ,
Posted in PHP | No Comments »

Allow Google analytics on private page | PHP

Tuesday, October 13th, 2015

<?php $allow_inside = ($is_logged_in) || substr_count($_SERVER['HTTP_USER_AGENT'],'Googlebot'); ?>

Tags: , , , , ,
Posted in PHP | No Comments »

Query custom post type based on custom field | WordPress

Monday, October 5th, 2015

<?php 
$cityname = get_field('city_name');

$args = array(
	'posts_per_page' => '100',
	'post_type' 	 => 'neighborhood',
	'meta_key'	 => 'city_n',
	'meta_value'	 => $cityname,
	'order'	         => 'asc'
);

$cityquery = new WP_Query($args);
$i = 1;
while ( $cityquery->have_posts() ) : $cityquery-> the_post();?>

Tags: , , , ,
Posted in PHP, WordPress | No Comments »

Display only child posts of parent | WordPress Query

Monday, July 27th, 2015

$args = array(
	'post_type' => 'page',
	'post_parent' => $post->ID,
);

Tags: , , , ,
Posted in PHP, WordPress | No Comments »

WordPress menu

Friday, December 12th, 2014

1) Register the menu in your functions.php file (Primary is the ID for the menu, Primary Menu is the name and Theme-name is the name of your theme)

register_nav_menus( array(
    'main_menu' => 'Main Navigation',
    'footer_menu' => 'Footer Menu',
    'legal_menu' => 'Legal Menu',
));

2) Enter this in to the location in your theme file where the menu will go (normally header.php)

<?php wp_nav_menu( array( 'theme_location' => 'primary' ) );?>

Tags: , , , , ,
Posted in PHP, WordPress | No Comments »

« Previous Page