Hot answers tagged title
12
Updating the posts
$all_posts = get_posts(
'posts_per_page' => -1,
'post_type' => 'post'
);
foreach ( $all_posts as $single ) {
wp_update_post( array(
'ID' => $single->ID,
'post_title' => to_title_case( $single->post_title ) // see function below
));
}
Converting a string to "Title Case"
And, while not ...
7
add_filter('admin_title', 'my_admin_title', 10, 2);
function my_admin_title($admin_title, $title)
{
return get_bloginfo('name').' • '.$title;
}
You could also do a str_replace on $admin_title to remove "— WordPress" and change "‹".
Look at the top of the wp-admin/admin-header.php file to see what is going on by default.
7
The easiest workaround could be:
function myplugin_update_slug( $data, $postarr ) {
if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] = sanitize_title( $data['post_title'] );
}
return $data;
}
add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 99, 2 );
6
This is possible by filtering wp_nav_menu_objects, which is the easiest place to check which item is the current menu item, because WordPress already added the classes for you.
add_filter( 'wp_nav_menu_objects', 'wpse16243_wp_nav_menu_objects' );
function wpse16243_wp_nav_menu_objects( $sorted_menu_items )
{
foreach ( $sorted_menu_items as $menu_item ) ...
6
There is no documentation on it but you could always apply a filter to the_title like this:
add_filter('the_title','some_callback');
function some_callback($data){
global $post;
// where $data would be string(#) "current title"
// Example:
// (you would want to change $post->ID to however you are getting the book order #,
// but you ...
5
you can use this function that jumps by google "get post by title"
/**
* Retrieve a post given its title.
*
* @uses $wpdb
*
* @param string $post_title Page title
* @param string $post_type post type ('post','page','any custom type')
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
* @return mixed
*/
function ...
5
In WordPress, "---" and " -- " become em-dashes (— —) and "--" becomes an en-dash (— #8212;). The sanitize_title_with_dashes() function doesn't catch these.
That function uses the databased copy, but the title displayed to the user always goes through a texturize function. So if we replace en/em dashes on their way into the database, ...
5
I would do it this way:
functions.php
<?php
add_filter( 'posts_where', 'title_like_posts_where', 10, 2 );
function title_like_posts_where( $where, &$wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( ...
5
You can globalize $post to work out the post type.
Example:
add_filter( 'the_title', 'add_the_title_prefix' );
function add_the_title_prefix( $title )
{
global $post;
if ( 'custom_post_type_name' != $post->post_type )
return $title;
return "<span>Press:</span> {$title}";
}
5
Disable all plugins. One of them puts all words with capital letters in a <span class="caps"> container. In
<meta property="og:title" content="test <span class="caps">CSS</span> title" />
… this closes the <head> section automatically because output is not allowed in <head>.
If you have found the plugin tell its ...
5
Assuming this question is related to Wordpress, here is answer :- You can update the titles directly into your mySQL database using simple update function.
one of my user publishs all his posts uppercase (title) i want to edit them and make it normal. –
Using some conditional statements as I mentioned in this code, you can restrict the update for ...
5
Hook into the_post – called when the post is actually used – and fill the title. Be aware the slug has to be changed too.
If you are used not to enter a title, hook into save_post too, and let the same code do this for you.
The code
Download on GitHub
<?php
/**
* Plugin Name: T5 Lazy Title Updates
* Description: Fill missing post titles from content ...
4
I'm trying to do this right now as well. The filter function seems like the best bet.
This is where I'm at now, but I can't seem to get the title of the next or previous post and pass it to the filter.
Edit: Figured it out. A bit hackey probably, but it works.
add_filter('next_post_link','add_title_to_next_post_link');
function ...
4
To add an extra class when there is no title
<h1<?php if(!get_the_title()){echo ' class="no-title"';}?>><?php the_title();?></h1>
Or to only display h1 tags when there is a title
<?php if(get_the_title()) { ?>
<h1><?php the_title();?></h1>
<?php }?>
4
You can use the widget_display_callback (fired, predictably, just prior to displaying a widget :) ).
add_filter('widget_display_callback','wptuts54095_widget_custom_title',10,3);
function wptuts54095_widget_custom_title($instance, $widget, $args){
if ( is_single() ){
//On a single post.
$title = get_the_title();
...
4
You can use your own hook for widget_title action. You can determine specific widget by $id_base parameter which is passed as third argument to the hook. It should work like this:
function myplugin_widget_title( $title, $instance, $id_base ) {
if ( !is_single() ) {
return $title;
}
$post_title = get_the_title();
switch ( $id_base ) ...
4
You can use markup in titles. H<sub>2</sub>O will work just fine. I would use H₂O with a real ₂ because markup will be stripped in title attributes and in feeds.
Note that WordPress will not create a pretty permalink for the correct character. The slug for my example will look like this: h2o-h%e2%82%82o.
You need my plugin Germanix URL to get ...
4
You could change the post title when it is viewed:
add_action( 'the_post', 'wpse_94856_title_update' );
function wpse_94856_title_update( $post )
{
if ( empty ( $post->post_title ) )
return;
$new_title = mb_convert_case( $post->post_title, MB_CASE_TITLE, "UTF-8" );
if ( $post->post_title === $new_title )
return;
...
4
To list all pages with title and permalink from one user you need $wpdb->get_results(). The following code is based on this answer: How to count current user's pages?
First, we move the counter into a separate helper function; we might need it later again:
/**
* Get all post IDs and titles of a type for a user.
*
* @param int $user_id
* @param ...
4
I am not sure I understand your issue right, but my guess is your conundrum - how to get to the title that is unchanged by your filter, if you are filtering it everywhere?
You can use get_post_field() function to get a raw copy of it from the post object.
However instead of messing with output (and making your saved data dependent on filters being present) ...
3
This sounds like an additional Loop on that page, right?
You might want to use:
<ul>
<?php $posts_query = new WP_Query('posts_per_page=5');
while ($posts_query->have_posts()) : $posts_query->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
...
3
You can try the following code.
function custom_post_type_title ( $post_id ) {
global $wpdb;
if ( get_post_type( $post_id ) == 'cars' ) {
$engine= ', '.get_post_meta($post_id, 'Engine', true).'l';
$terms = wp_get_object_terms($post_id, 'brand');
$abrand= ' '.$terms[0]->name;
$amodel = ' '.$terms[1]->name;
...
3
Despite what the Codex says, $postarr doesn't always get passed in, so you should just use $data. $data isn't a meaningful variable name, though, so I prefer $cleanPost. I'd also try removing the priority on the filter, since it's not usually necessary. It's also a good idea to set the slug (post_name) in addition to the title, and to avoid running the code ...
3
I see my name in the title when viewing author pages.
wp_title() runs this code during execution..
// If there's an author
if ( is_author() ) {
$author = get_queried_object();
$title = $author->display_name;
}
Perhaps your author(s) don't have a display name set?
Additionally be sure to try disabling plugins that may be hooking a filter ...
3
I've seen there are some plugins to work around this problem. Check Clean URL for example:
This simple WordPress plugin is used
when generating article slug (=
article name used in URL). It removes
all characters other than letters a-z,
numbers and hyphens (-). The plugin
runs as the last one in the whole
url-generating process, so first all
...
3
By using wp_update_post(), found in wp-includes/post.php:
// Update post 42
$post = array();
$post['ID'] = 42;
$post['post_category'] = array( ... );
$post['post_content' ] = 'This is the updated content.';
$post['post_title' ] = 'This is the updated title.';
// Update the post into the database
wp_update_post( $post );
3
I'm not sure how to get it via the title, but you can get it via the slug (which is often more useful in my experience) using this:
http://erikt.tumblr.com/post/278953342/get-a-wordpress-page-id-with-the-slug
Just change "$page" to "$post" if you want to return slugs for posts instead of pages.
G'luck!
3
You can exclude menus by testing the post id :
add_filter( 'the_title', 'add_cpt_prefix' );
function add_cpt_prefix( $title ) {
global $id, $post;
if ( $id && $post && $post->post_type == 'press' ) {
$title = '<span>Press:</span> ' . $title;
}
return $title;
}
3
This part comes from the function comment_form() which is called by your theme, probably in comments.php:
'comment_notes_after' => '<p class="form-allowed-tags">'
. sprintf( __(
'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags
and attributes: %s' ), ' <code>' . allowed_tags() . ...
3
This is because the_title() echos the post title (see the linked documentation). Use get_the_title() instead which returns the title as a string.
Edit
You have two options:
Use get_the_title() to return, rather than echo, the post title
Filter the_title to echo a custom string as the post title
Using get_the_title()
<?php
// NOTE: Inside the Loop,
...
Only top voted, non community-wiki answers of a minimum length are eligible