WP action/filter to modify title before header output and article output?

The filter wp_title changes only the function wp_title() when it’s called. So, you must double check on your theme’s source code if before your header is using wp_title. Anyway, you can set your filter on functions.php. A function to identify your param GET should be something like so: function maybe_change_wp_title_ver( $title, $sep ) { if … Read more

Custom post type title is set by other custom post type

I found that i just have to use $post->post_name instead of $post->post_title because $post->post_name holds the slug also the autogenerated if you save as draft without defining a title. So the code would as follows global $post; $slug = $post->post_name; echo “<script>alert (‘”.$title.”)</script>”; $args = array( ‘post_type’ => ‘traener’, ‘posts_per_page’ => -1, ‘orderby’ => ‘post_title’, … Read more

How do I hide the current page’s title?

You can try this function wpb_hidetitle_class($classes) { if ( is_single() || is_page() ) : $classes[] = ‘hidetitle’; return $classes; endif; return $classes; } add_filter(‘post_class’, ‘wpb_hidetitle_class’); CSS code : .hidetitle .entry-title { display : none; } Source http://www.wpbeginner.com/plugins/how-to-hide-post-and-page-titles-in-wordpress-single-pages/

How to sanitize post title with commas

Depending on how you are outputting the title, the answer is different. But there are two possibilities. By Using wp_title(); If your theme is using the wp_title(); function in its header.php file, you can use the wp_title filter. However, this function is being deprecated since 4.4. add_filter( ‘wp_title’, ‘filter_the_title’ ); function filter_the_title( $title ) { … Read more

the_title gives me the page’s title not the post title in the following code

You are using the default page loop and it will output the current page attributes like title or other. You should create your own loop with custon query instead. See WP_Query or get_posts. Example $query = new WP_Query(array( ‘post_type’ => ‘post’, ‘posta_status’ => ‘publish’, )); if($query->have_posts()){ while($query->have_posts()){ $query->the_post(); echo get_the_title(); } wp_reset_postdata(); }

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

get_posts() loop returns the same the_title() for each post

Making Milos’s comment into an answer…. The problem you are facing is the result of many wordpress template oriented functions expect some global variables. In WP_Query based loops setting those variable is done by calling the the_post() method of the WP_Query object, but with get_posts you need to call setup_postdata() for that. My personal preference … Read more