- This topic has 12 replies, 2 voices, and was last updated 4 years, 10 months ago by
Pete.
-
AuthorPosts
-
December 29, 2014 at 6:13 am #59117
Pete
Can we please have some extra hooks…
archive.php
- before and after the category title
- before and after the category description
Thanks
December 30, 2014 at 6:58 pm #59931Pete
December 31, 2014 at 7:09 pm #60335Pete
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;
}
December 31, 2014 at 7:24 pm #60336Pete
Unfortunately the echoing before the single cat title screws up the cat page title
December 31, 2014 at 7:27 pm #60337Pete
This can be fixed with Yoast’s SEO plugin with
Force rewrite titles
ticked.December 31, 2014 at 8:03 pm #60338Pete
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; }
December 31, 2014 at 8:57 pm #60346Pete
OK I’ve added in the shortcode function so now no plugins are needed… I’ll make a new post.
January 1, 2015 at 10:58 am #60542Tom
Lead DeveloperLead DeveloperI’ll take a look at adding those hooks as well ๐
Thanks!
January 1, 2015 at 7:24 pm #60682Pete
Hi Tom there’s no hook in content-single.php between
.entry-content
and.entry-meta
. A hook here would be very useful. ๐January 3, 2015 at 12:26 am #61096Tom
Lead DeveloperLead DeveloperThanks for letting me know – will look at that as well.
January 3, 2015 at 6:04 pm #61336Tom
Lead DeveloperLead DeveloperI’ve added all of these hooks to 1.2.5.
Thanks!
January 3, 2015 at 6:10 pm #61338Pete
Awesome thanksTom.
November 24, 2018 at 4:56 am #737274Pete
resolved
-
AuthorPosts
- You must be logged in to reply to this topic.