Jump to content
Sign in to follow this  
patrick6000

adding custom field value to the title of posts ads it to the menu too

Recommended Posts

patrick6000

I made a filter to add a custom field value to the title of posts. The custom field value also appears in the menu. Do you know how to avoid this ? here is the filter i've added to functions.php

function une_numero($content){
			$post= get_post($id);
			if (get_post_meta($post->ID,'Numero',true)){
			$num = get_post_meta($post->ID,'Numero',true);
			$my_new_title = '#'. $num .' | '. $content;
			return $my_new_title;}
			else{
			return $content;
			}
		}
			add_filter('the_title','une_numero');

Share this post


Link to post
Share on other sites
bryan-hadaway

Appears in the menu of the front-end view of your site? Let's get a link. Thanks, Bryan

Share this post


Link to post
Share on other sites
cmunns

The easiest way to avoid would be to create a menu manually using WP3.0 menu system under APPEARANCE - MENUS Create a menu by naming it - add items from the left - save it - add it to the proper theme location and save again and you're good (drag and drop to create dropdowns)

Share this post


Link to post
Share on other sites
patrick6000

it affects the page nav above the post and the main menu

Share this post


Link to post
Share on other sites
Kate

@Martin I'm not seeing the issue, unless I misunderstood what it is. Did you get it working the way you want?

Share this post


Link to post
Share on other sites
patrick6000

@kate Yes, i've got it working. Here's the filter

		function myfunction($content){
			global $wp_query;
			$post_id = $wp_query->post->ID;
			if (get_post_meta($post_id,'mycustomfield',true)){
			$num = get_post_meta($post_id,'mycustomfield',true);
			echo '#'. $num .' | '. $content;}
			else{
			echo $content;
			}
		}
	add_filter('pagelines_loop_posttitle_start','myfunction');
	
I changed
return $content
to
echo $content
and used
pagelines_loop_posttitle_start
instead of
the_title

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×