fbpx

How to create new template without FTP/Cpanel

If you are working on a live WordPress site, there might come a time when you would need to upload a new theme file. This is common if you are creating new templates for a WordPress Theme.

Go to your WordPress theme editor. http://yoursite.com/wp-admin/theme-editor.php

Edit the header.php file and add the following code at the very top or the first line.

<?php touch('wp-content/themes/theme-name/new-file.php'); ?>

 

PHP – new-template.php, new-function.php
CSS – new-style.css, page-style.css

Make sure to add it outside any <?php tags otherwise it could cause an error since the code is already wrapped in its own PHP tags.

Save the changes made to the header.php file. Open a new tab in your browser then visit the website. The new file will be created.

You can now remove the code from the header.php.

How to Remove width & height attributes from images in posts

Looking to remove the width and height attributes from images in your posts? Is this because you are using a responsive wordpress theme. Just add this snippet to the functions.php of your wordpress theme and all of the width and height attributes will be removed from your images.

add_filter( 'post_thumbnail_html', 'remove_wps_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_wps_width_attribute', 10 );
 
function remove_wps_width_attribute( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}

How to Convert a date / timestamp to time ago for posts

Displaying an exact date on your posts is great but why not change things up just a little and display “1 Hour Ago, 2 Hours Ago, 1 Day Ago, 2 Days Ago, 1 Week Ago, etc. Just add this snippet to your single.php, index.php or any other template within the loop and you are good to go.

echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';

How to Display theme information with wp_get_theme

Adding this snippet to your wordpress theme will let you display data from your theme file. name, title, uri, description, authorURI, template, version, status, tags, author. We have updated this snippet to coincide with the most recent changes to wordpress.

<?php
$theme_data = wp_get_theme();
echo $theme_data->get( 'Name' );        // Theme name as given in style.css
echo $theme_data->get( 'ThemeURI' );
echo $theme_data->get( 'Description' );
echo $theme_data->get( 'Author' );
echo $theme_data->get( 'AuthorURI' );
echo $theme_data->get( 'Version' );
echo $theme_data->get( 'Template' );
echo $theme_data->get( 'Status' );
echo $theme_data->get( 'Tags' );
echo $theme_data->get( 'TextDomain' );
echo $theme_data->get( 'DomainPath' );
?>

How to Remove <p> and <br/> from Contact Form 7

Contact form 7 is a great tool but sometimes it adds a little extra HTML that you might want to get rid off within your page, posts. Adding this snippet to your wp-config will remove all of the extra and from your forms. Add the code on functions.php

define('WPCF7_AUTOP', false );