Skip to content

Instantly share code, notes, and snippets.

@djave-co
Last active December 25, 2015 16:19
Show Gist options
  • Save djave-co/7005128 to your computer and use it in GitHub Desktop.
Save djave-co/7005128 to your computer and use it in GitHub Desktop.

Home URL

home_url()

Useful for a link to the home directory.

<a title='Home' href='<?php echo home_url(); ?>'>Home</a>

Stylesheet Directory

get_stylesheet_directory()

Useful for using images in the stylesheet directory. NB use echo.

<img src="<?php echo get_stylesheet_directory_uri();?>/img/logo.jpg" />

Get Permalink

get_permalink($post_id);

Gets the URL to a page from its ID.

echo get_permalink(2);
// echos http://localhost.sites/worth/about

Get Page ID

get_page_by_path( 'about' );

Grabs the page or posts id, using only its slug. Useful when you don't know what the page's id is and you need a permalink. You can pass it to the above permalink function as an argument.

echo get_page_by_path( 'about' );
// echos 2
echo get_permalink( get_page_by_path( 'about' ) );
// echos http://localhost.sites/worth/about

Get Term (Tag) Page URL

get_term_link( $term_name, $taxonomy );

Gets the page link for the term archive of a certain taxonomy.

echo get_term_link( 'cute', 'tags' );

Set up images

// First, set an action to trigger when Wordpress starts
add_action( 'init', 'MS_image_sizes' );

// In that action, add the image sizes
function MS_image_sizes(){
    // add_image_size( $name, $width, $height, $crop );
	add_image_size( 'magazine-thumb', 87, 115, true );
}

Next up we can recover the size of thumbnail using the the_post_thumbnail();

the_post_thumbnail('magazine-thumb');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment