• tasver85

    (@tasver85)


    Hi, i’m trying to pass the “Theme unit test” on a development alpha site.
    This is my first experience in html, css, php and wordpress, i’m a noob.

    I would like to insert a title like “No title” into the post without the title and without the permalink.

    This post is in the “Theme unit test” but i can’t find the way to insert the permalink on the date as the post suggest.

    The post in the website is the fourth on page 4 https://filmandnovel.altervista.org/blog/page/4/

    This is what the post says.

    This post has no title, but it still must link to the single post view somehow.

    This is typically done by placing the permalink on the post date.

    And this is my code for getting the title and permalink,

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
    		<?php the_title(); ?>
    		</a></h2>

    i tried many solution with if and else but nothing worked and still no title appear.

    Thanks for your attention

Viewing 1 replies (of 1 total)
  • I’m not sure if there are other ways to do it, but I usually use the ‘the_title’ filter hook.
    Try something like this:

    function stham_the_title ( $title ) {
    
    	if ( in_the_loop() && ! is_page() ) {
    		if ( ! $title )
    			$title = __( 'No title', 'stham' );
    	}
    	return $title;
    
    }
    add_filter( 'the_title', 'stham_the_title' );

    However, the above only changes the title in the blog listing page (if I remember correctly). The title could still be blank in other spots, e.g. between your <title> tags (you can use the ‘wp_title’ filter hook for that). I can’t quite remember now what other spots might still be sporting a blank post title. Just check carefully when you’re doing your testing.

    For more info:
    Hooks
    the_title
    wp_title

    I may be wrong here but I believe all posts will have permalinks. WordPress will auto-generate the permalink based on your post’s title. If there’s no title, I believe it uses the post’s ID.

    Also, the_title() is not suitable to be used as part of the title attribute in a link. Use the_title_attribute() instead.

    Hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Post without title insert permalink’ is closed to new replies.