Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Replace post/page title on home, single and archive pages.
- *
- * @param string $title Post title
- * @param int $post_id Post ID
- *
- * @return string New post tilte
- */
- function wpse_309151_get_replace_default_title_from_meta( $title, $post_id ) {
- $post_type = get_post_type( $post_id );
- if( $post_type === 'post') {
- $disc_link = '#';
- $dis_text = 'Commerce Content is independent of Editorial and Advertising, and if you buy something our posts, we may get a small share of the sale';
- $dis_text_two = 'for more';
- $new_title = sprintf('<div class="bashar-amazon-dis-text"><p>%s <a href="%s">Click Hare</a> %s</p></div>', $dis_text, $disc_link, $dis_text_two);
- if( $new_title && !empty( $new_title ) ) {
- return $new_title.$title;
- }
- }
- return $title;
- }
- add_filter( 'the_title', 'wpse_309151_get_replace_default_title_from_meta', 10, 2 );
- /**
- * Restore default post/page title in navigation
- *
- * @param string $title The menu item's title.
- * @param WP_Post $item The current menu item.
- * @param stdClass $args An object of wp_nav_menu() arguments.
- * @param int $depth Depth of menu item. Used for padding.
- *
- * @return string Restored post title
- */
- function wpse_309151_get_restore_default_title_for_navigation( $title, $item, $args, $depth ) {
- // Remove filter to not affect title
- remove_filter( 'the_title', 'wpse_309151_get_replace_default_title_from_meta', 10, 2 );
- $post_id = $item->object_id;
- $title = get_the_title( $post_id );
- // Add the title filter back
- add_filter( 'the_title', 'wpse_309151_get_replace_default_title_from_meta', 10, 2 );
- return $title;
- }
- add_filter( 'nav_menu_item_title', 'wpse_309151_get_restore_default_title_for_navigation', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement