© Toffy Digital The sweetest digital solutions 2019

Category: WordPress

Use the following function to get Post Slug in body class

//Page Slug Body Class function add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $post->post_type . ‘-‘ . $post->post_name; } return $classes; } add_filter( ‘body_class’, ‘add_slug_body_class’ );

Read More

Use this code to hide text editor on certain pages or templates

<?php /** Hide editor on specific pages. */ add_action( ‘admin_init’, ‘hide_editor’ ); function hide_editor() { // Get the Post ID. $post_id = $_GET[‘post’] ? $_GET[‘post’] : $_POST[‘post_ID’] ; if( !isset( $post_id ) ) return; // Hide the editor on the page titled ‘Homepage’ $homepgname = get_the_title($post_id); if($homepgname == ‘Homepage’){ remove_post_type_support(‘page’,…

Read More

Simple function to list all Categories a single post is listed in

function listSinglePostCategories($post_id){ $wpcats = wp_get_post_categories($post_id); $cats = array(); foreach ($wpcats as $c) { $cats[] = get_cat_name( $c ); } $lister = implode(“, “, $cats); return $lister; }

Read More

List categories with Posts (Using custom post types and custom taxonomies)

The following code easily lists a set of Categories (taxonomies or custom taxonomies) followed by a loop of posts that follow it.

Read More

Change the author of a post in WordPress

To change the author of a post first go to and open a post. Now open the “Screen options” that you find right at the top of the post edit page.   Now click the author check box:   You should now be able to see the Author row appear…

Read More

Get post ID’s

Use the following code to get the post ID of a WordPress page

Read More

WordPress Dash incons

Can be used with your custom post types Link reference: Dashicons

Read More

Adding custom post types (CPT) without a plugin

Very simply try adding this to your wpt_cpt.php file and explore what this does for your WordPress site. In a nutshell, this adds a new post type that you can now define in WordPress.

Read More

WordPress disable admin navigation bar

To disable the admin navigation bar. Apply the following script to the function.php file. /* Disable the Admin Bar. */ add_filter( ‘show_admin_bar’, ‘__return_false’ );  

Read More

WordPress import Google fonts done the right way

Load fonts into your templates using Functions method as shown below: <?php function load_fonts() { wp_register_style(‘googleFonts’, ‘https://fonts.googleapis.com/css?family=Play:400,700|Roboto:400,700,900’); wp_enqueue_style( ‘googleFonts’); } add_action(‘wp_print_styles’, ‘load_fonts’); ?> This way the fonts are embedded for child themes and can be used when pages are printed to PDF.

Read More