0

I am a beginner in WordPress Development wanted to get some help. Iam working on a simple WordPress site. Basically the user wants the most recent post to show on the homepage. I've used the Latest Posts Block and I've set it to show the entire Post Content and now the user does not want the title of the post to be linked to the individual post page (since the contents of the post show on the homepage).

How do I safely modify the template file to use like a something like a h2 tag instead of a href tag, which is used here in the theme. I know you can create a child theme and modify wp_content files, but I am not sure how to approach this with files in wp_include. I read something about modifying functions.php but I am not sure and would appreciate any pointers.

$title = get_the_title($post);
        if (!$title) {
            $title = __('(no title)');
        }
        $list_items_markup .= sprintf(

            '<a href="%1$s">%2$s</a>',
            $post_link,
            $title
        );

1
  • if there's no link to the post, how would I share it directly with someone or on social media? There are SEO consequences to this too
    – Tom J Nowell
    Oct 11, 2021 at 11:48

1 Answer 1

0

This really depends on your theme. Somewhere in its template files the title is generated, including the anchors. This differs per theme, but you'll have to look for something like this:

echo '<a href="'. get_permalink . '">' . get_the_title . '</a>';

If it is hard coded like this, you'll have to choice but to override it by making a child theme, copying the template file where you found this and replace it with

if (is_front_page) echo get_the_title;
else echo '<a href="'. get_permalink . '">' . get_the_title . '</a>';

Note that, depending on the theme, things may be a lot more complicated than this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.