How to add custom format WordPress and alter template

This article was written by in August 9, 2014, & may not be posted on other sites!
Original source url for this article: How to add custom format WordPress and alter template

How to add custom format WordPress? How to alter format template?
Creating a new post in WordPress, you have the option of choosing a post format, for example “aside”, “image” or “Quote” (in the Format panel on the right). It is not possible to add an additional custom format, but it is possible to alter an exisitng one. This is how to create a custom format in WordPress.

 

Supported formats in WordPress:

aside – No title note type format
gallery – A gallery type format.
link – The post links to another site.
image – A single image in focus.
quote – A quotation type post.
status – A short status update type post.
video – A single video or video playlist type post.
audio – An audio file or playlist type post for example podcasting.
chat – A chat transcript type post.

 

 

How to add custom format WordPress and alter template

To make your theme support a missing format in WordPress

To add one or more missing formats to your theme, use this code in your functions.php
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

Working with a child-theme, try this code instead. Put it in your childtheme functions.php file.
add_action( 'after_setup_theme', 'childtheme_formats', 11 );
function childtheme_formats(){
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link' ) );
}

 

How to change the name of an existing format in WordPress

To alter an existing format and make it your own custom format in WordPress, start by changing the name/names by adding this code to your functions.php:
function rename_post_formats($translation, $text, $context, $domain) {
$names = array(
'Aside'  => 'Custom 01',
'Audio' => 'Custom 02'
);
if ($context == 'Post format') {
$translation = str_replace(array_keys($names), array_values($names), $text);
}
return $translation;
}
add_filter('gettext_with_context', 'rename_post_formats', 10, 4);

 

 

How to alter an existing format template in WordPress

If your parent theme already supports for example the “aside” format, just copy the content-aside.php file from your parent theme to your child theme, and alter it however you like. The content-aside.php is used by all posts with format “aside”.

 

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *