Site logo

Archived topic

Extra GP Hooks

12 replies · Started by Pete on December 29, 2014

Viewing posts 1–13 of 13

Can we please have some extra hooks...
archive.php

  • before and after the category title
  • before and after the category description

Thanks

This dynamically allows you to put some php code after the category title as well as some text/html before and after the category title.

Place the below code inside your functions.php

You need to install the Real-Time Find and Replace plugin as well, as explained in the code below.

add_filter( 'single_cat_title', 'before_after_code_single_cat_title' );

function before_after_code_single_cat_title( $text ) {
	/*** important info ***/
	/*** 
	you need to install the Real-Time Find and Replace plugin to hide the original h1 tags. Use the following find text. Copy all in between the [] (make sure you keep the spaces).
	
	[<h1 class="page-title">
					hide</h1>]
	***/ 
	echo 'hide</h1>';
	echo '<p>Before the category title</p>';
	echo '<h1 class="page-title">';
	
	//YOUR CODES HERE - MUST BE STRING MANIPULATIONs; example://
	$append = '';	
	// Show an optional term description.	
	$term_description = term_description();
	if ( ! empty( $term_description ) ) :

	$append .= sprintf( '<div class="taxonomy-description2">%s</div>', $term_description );

	$text = $text . '</h1><p>Text after the category title and before the code insertion is optional</p>' .  $append . ' <p>Text after the code insertion is optional</p>';
	endif;
 
	return $text;

}

Unfortunately the echoing before the single cat title screws up the cat page title

This can be fixed with Yoast's SEO plugin with Force rewrite titles ticked.

Modified code, using 1 plugins as per the comments...

add_filter( 'single_cat_title', 'code_before_single_cat_title' );
function code_before_single_cat_title( $text2 ) {
	$append2 = '';	
// Use the Shortcode Exec PHP plugin to convert your code into a shortcode and insert it here	
	$append2 .=  do_shortcode('[text2]' );
	$text2 = '</h1>' .  $append2 . '<p>Some text/html can be inserted after the top code here</p><h1 class="page-title">' .  $text2 . '</h1><p>Some text/html can be inserted after the category title here</p>';
	return $text2;
} 
  
add_filter( 'single_cat_title', 'before_after_code_single_cat_title' );
function before_after_code_single_cat_title( $text ) {
	$append = '';	
// Use the Shortcode Exec PHP plugin to convert your code into a shortcode and insert it here 
	$append .=  do_shortcode('[text]' );
	$text = $text . '</h1><p>Some text/html can be inserted before the bottom code here</p>' .  $append . ' <br /><p>Some text/html can be inserted after the bottom code here</p>';
 	return $text;
}

OK I've added in the shortcode function so now no plugins are needed... I'll make a new post.

I'll take a look at adding those hooks as well :)

Thanks!

Hi Tom there's no hook in content-single.php between .entry-content and .entry-meta. A hook here would be very useful. :)

Thanks for letting me know - will look at that as well.

I've added all of these hooks to 1.2.5.

Thanks!

Awesome thanksTom.

resolved

This archived topic is closed to new replies.