Including a post title in a twitter link

The problem is that get_the_title() will pass the title through a filter that texturizes the quotes. So a regular ” becomes a curly quote (“) and urlencode() will break it. So instead, write your own title function and use that: function my_get_the_title() { global $post; return $post->post_title; } This should bypass any unwanted filters and … Read more

Can’t get title of latest post

You’re getting there! Couple of issues – you need to actually grab the latest posts before you can work on them. And post_title is not a property of the ID, but the object itself: if ( $posts = get_posts( ‘numberposts=1’ ) ) { $title = $posts[0]->post_title; // carry on sir } Note: Ensure you have … Read more

How to change the page title from functions.php

If you refer to the post title you need to hook your function to the_title filter like explained in the codex. add_filter(‘the_title’, ‘my_custom_title’, 10, 2); If you refer to the HTML meta in your page then you need to hook your function to document_title_parts filter explained here. add_filter(‘document_title_parts’, ‘my_custom_title’, 10, 2); The two filters work … Read more

get_title without filter(the_title)

There’s a few ways to do this, but I would argue that the preferred way is, in general, fetching the post_title attribute from the post object. This does not depend on removing all filters for a certain function and adding them back later — the latter requires you to directly access the global $wp_filter. get_post … Read more

Filter get_the_title to remove certain characters?

The function the_title() is just a wrapper around the function get_the_title(). It’s understandably confusing that the filter the_title actually exists inside get_the_title(). So, whatever the function you’re using to actually display it, it doesn’t matter, you can filter its content by hooking into the_title

How to intercept Post Title on Post-Save

To set the title before it is saved, hook into wp_insert_post_data: add_filter( ‘wp_insert_post_data’, ‘wpse_75597_change_title’ ); function wpse_75597_change_title( $post_data ) { $post_data[‘post_title’] = ‘SOMETHING VERY LOUD’; return $post_data; }

Multiple Conditions for Child Page Title

Based on the comment exchange, here’s what I think you’re after: <h1><?php echo get_the_title( $post->post_parent ? $post->post_parent : $post->ID ) ?></h1> <?php if ( $list = wp_list_pages( “echo=0&child_of=$post->ID” ) ) : ?> <h2>Select a sub-page</h2> <ul> <?php echo $list ?> </ul> <?php elseif ( $post->parent ) : ?> <h2><?php the_title() ?></h2> <?php endif ?>