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 ?>

How to display thumbnail + tags + title of a child page?

Assuming that you’ve enabled support for both post thumbnails and post tags for static Pages, I would use WP_Query() to build your query, and do something like the following: global $post; $child_pages_query_args = array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID, ‘orderby’ => ‘menu_order’ ); $child_pages = new WP_Query( $child_pages_query_args ); if ( $child_pages->have_posts() ) : … Read more

custom field to always to .get_the_title()?

<?php function add_subtitle($title, $id) { $subtitle = get_post_meta($id, ‘myCustomField’, true); $new_title = $title; if(!empty($subtitle)) $new_title = $subtitle . ‘: ‘ . $new_title; return $new_title; } add_filter(‘the_title’, ‘add_subtitle’, 10, 2); Basically, this uses the the_title filter to add the subtitle to your title. It only adds it if that custom field is available, otherwise, it leaves … Read more

get the_title_attribute by id

hey just look in code and it also support fourth parameter post global $post; the_title_attribute(array(‘post’=>$post));//post object or global $post; the_title_attribute(array(‘post’=>$post->ID));//post id so you can use it like <a href=”https://wordpress.stackexchange.com/questions/111931/<?php echo get_permalink($id); ?>” title=”<?php the_title_attribute(array(‘post’=>$id)); ?>”> //where $id is post id Important Link the_title_attribute

posts order by title second word

The simplest method may be to just save titles as last name / first name, then they will naturally sort. You can then reverse the title when you output it in the template. Your attempt to modify the orderby query var is fundamentally flawed. Order is created by MySQL, which doesn’t understand PHP, and can’t … Read more