CodeHQ

Archive for the ‘PHP’ Category

« Older Entries | Newer Entries »

Hiding WP-Login page | WordPress

Saturday, May 21st, 2016

Using the below code in your functions.php file, you would then only be able to access the WP dashboard by navigating to domain.com/wp-login.php?admin=access.

// Hiding wp-admin and wp-login.php 

function protection_for_login_page() {
$QS = '?admin=access';
$theRequest = 'http://' . $_SERVER['SERVER_NAME'] . '/' . 'wp-login.php' . '?'. $_SERVER['QUERY_STRING'];

	if ( site_url('/wp-login.php').$QS == $theRequest ) {
		echo 'Query string matches';
	} else {
		header( 'Location: http://' . $_SERVER['SERVER_NAME'] . '/' );
	}
}
add_action('login_head', 'protection_for_login_page');

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

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 »

Display search term | WordPress

Friday, April 29th, 2016

<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"

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

Using media gallery image sizes with ACF | WordPress

Friday, March 25th, 2016

You can use thumbnail, medium, large or full as the sizes variable to serve the size image you require.

<?php $image = get_field('the_image'); ?>
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['caption']; ?>" />

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 »

ACF – Flexible content | WordPress

Wednesday, February 24th, 2016

Useful code for Advanced custom fields (ACF) flexible content – perfect for page builders

<?php
if( have_rows('pagebuilder') ):
    while ( have_rows('pagebuilder') ) : the_row();
        if( get_row_layout() == 'hero' ):
        	
        	get_template_part( 'assets/parts/pagebuilder/hero');
     
		elseif( get_row_layout() == 'call_to_action' ):
		
        	get_template_part( 'assets/parts/pagebuilder/call-to-action');
 
        endif;
    endwhile;
else :
    // no layouts found
endif;
?>

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

Time ago date format | PHP

Wednesday, January 20th, 2016

To set your time up as ’12 days ago’ instead of dd/mm/yyyy format.

Using ‘php time ago

<?php $timeAgo = new TimeAgo();
echo $timeAgo->inWords(get_the_time('jS F Y')); ?> ago

Tags: , , ,
Posted in PHP | 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 »

Next Page »« Previous Page