Skip to content
Back Home
  • Customizr Pro
  • Hueman Pro
  • Nimble Page Builder
  • Blog
  • Search
Back Home
  • Customizr Pro
  • Hueman Pro
  • Nimble Page Builder
  • Blog
Home » Snippets » WordPress functions » is_single() » Moving single post metas to the bottom of the post
code snippets html php Post metas Posts __after_content_title __after_loop __before_body __post_metas is_single() remove_action()

Moving single post metas to the bottom of the post

by Nicolas|Published 22 October 2013

⚠️ Code snippets might not be compatible with the latest version of your theme. Always use a child theme to customize your theme, and test your code on a staging website before migrating to production.

You can search the user’s forum or ask the user community by opening a new thread in the Customizr theme forum. Before opening a new topic, you might want to follow the troubleshooting steps..

Updated March 2015: This snippet now works only with Customizr > 3.3.1 and Customizr-Pro > 1.0.12

This little snippet gives a simple solution to display the post metas at the bottom of a single post in the Customizr theme, (instead of right below the post title).

This code has to be pasted in the functions.php of a child theme.

//we hook the code on the __before_body hook, which is executed before the <body> rendering.
add_action ('__before_body' , 'move_single_post_metas');

function move_single_post_metas() {
  //checks if we are displaying a single post. Returns false if not.
  if ( ! is_single() )
    return;
  //we remove the original action hooked on '__post_metas'. tc_post_metas action is a method of the TC_post_metas class
  //We can access the instance of this class with a static property of this class that is a self instance.
  remove_action  ( '__after_content_title' , array( TC_post_metas::$instance , 'tc_set_post_metas_hooks' ), 20);

  //we add the tc_post_metas action on a the __after_loop (check index.php file to see where this hook is called in the code)
  add_action ('__after_article' , array( TC_post_metas::$instance , 'tc_set_post_metas_hooks'), 10);

  //Additional action to display an hr separator between content and metas. 
  //We use the priority parameter to determine the rendering order of the action
  add_action ('__after_article' , 'display_hr', 0);

  //this is a nested function (function in another function), allowed with PHP.
  function display_hr() {
	?>
	  <hr/>
	<?php
  }
}

 

AUTHOR

Nicolas
Hi! I'm Nicolas (@presscustomizr), the lead developer of the Customizr Theme and the Hueman Theme. My team and I are working everyday to help you publish your WordPress content the best possible way. We love to do it!Thanks for visiting this website, feel free to drop us a line !
0 posts

You may also like

Changing the “Search” string in WordPress search forms
Published 5 March 2016

Changing the “Search” string in WordPress search forms

  Note about translations : before you start coding anything, note that the “Search” string in the search forms is a WordPress […]

Changing the post navigation’s texts
Published 6 January 2014

Changing the post navigation’s texts

The Customizr WordPress theme comes with default texts for navigation at the bottom of single posts and on post lists pages. There […]

Change the size of the Social Icons
Published 15 October 2013

Change the size of the Social Icons

Where to copy/paste this code? The simplest way is to use the Custom CSS section of the customizer option screen. If you […]

Add qTranslate flags with a navbar widget
Published 21 January 2014

Add qTranslate flags with a navbar widget

Learn how to add a widget for qTranslate and style your flags.

Impress your visitors with a perfect experience on smartphones

customizr-pro-screenshot

10K+ small businesses are already using the Customizr Pro WordPress theme for their online presence.

Discover Customizr Pro

Post navigation

  • Previous post Add a border underneath the Slider
  • Back to post list
  • Next post Remove Navbar Box
Useful pages
  • Your account
  • Product Support
  • Documentation
  • WP code snippets for Customizr theme
  • Work with us
Company
  • About
  • Blog
  • Privacy Policy
  • Terms of sale
  • Contact Us
Products and Services
  • Customizr Pro
  • Hueman Pro
  • Customizr WordPress Theme
  • Hueman WordPress Theme
  • Nimble Builder

© 2021 Press Customizr – All rights reserved