Print post title with markup
Using your example, you could… <h4><?php echo get_the_title( $post_id ); ?></h4> Or $h4 = get_the_title(); echo ‘<h4>’ . $h4 . ‘</h4>’; More on get_the_title(). Or you could use the_title(). the_title( ‘<h4>’, ‘</h4>’ );
Using your example, you could… <h4><?php echo get_the_title( $post_id ); ?></h4> Or $h4 = get_the_title(); echo ‘<h4>’ . $h4 . ‘</h4>’; More on get_the_title(). Or you could use the_title(). the_title( ‘<h4>’, ‘</h4>’ );
The “easy” answer is: put a filter on it. add_action( ‘transition_post_status’, ‘my_function’, 10, 3 ); function my_function( $new_status, $old_status, $post ) { if ( ‘publish’ !== $new_status or ‘publish’ === $old_status ) return; if ( ‘post’ !== $post->post_type ) return; // restrict the filter to a specific post type $title = $post->post_title; $restricted_title = “title … Read more
The code posted for your index.php file contains an error. The WordPress function the_post() is called twice in each iteration. As this function iterates the post index and sets up the conditionals for each post, calling this twice is the likely cause of your problem. Remove the second instance of the_post() immediately after your H2. … Read more
Let’s say you wanna prepend the word “Special: ” to every stick post’s title you can place the following in your functions.php: add_filter( ‘the_title’, ‘sticky_title’ ); function sticky_title( $title ) { // Check if a post is set to sticky. if ( is_sticky() ) { // Prepend “Special: ” to post title. return ‘Special: ‘ … Read more
You could use PluginPrePublishPanel to check for the title and lock publishing if it’s empty. Have a look at the accepted answer here for an example of locking the post – Add pre-publish conditions to the block editor For your example you could modify the checking portion as follows: const { registerPlugin } = wp.plugins; … Read more
You use the document_title_separator filter. So in your case: <?php function theme_prefix_filter_document_title_separator() { return ‘|’; } add_filter( ‘document_title_separator’, ‘theme_prefix_filter_document_title_separator’ ); ?>
You are getting the two <title> tags most likely because your theme has the title-tag support which automatically adds the title tags in the document head. Excerpt from the above linked page on Make WordPress Core: Adding titles to themes Starting with 4.1 and Twenty Fifteen, the recommended way for themes to display titles is … Read more
the_title filter takes two parameters, one of them is the ID of the post for which it was called. Something like that should work. add_filter( ‘the_title’, ‘se385007_title_filter’, 20, 2 ); function se385007_title_filter( $title, $post_id ) { $new_title = str_replace( “[geo_name]”, “[geo_name post_id=$post_id]”, $title ); return do_shortcode( $new_title ); )
It depends on your theme how exactly <title> is generated. At least some of it should be generated by wp_title() function, output of which you can filter at wp_title hook.
Something like this (not tested): add_filter(‘the_title_rss’, ‘custom_feed_title’); function custom_feed_title($title) { $headline = get_post_meta(get_the_id(), ‘headline’, true); if (!empty($headline)) return $headline; return $title; }