0

I have tried lots of different things with this, and clearly I just don't understand php and hyperlinks enough to figure it out.

I'm using this code to output a custom field's value at the bottom of that specific blog post:

   //* CUSTOM COMMENTS FIELD 
add_action( 'genesis_entry_footer', 'custom_comments_field' );
function custom_comments_field() {
if (  is_single() && genesis_get_custom_field('Comments link text') ) :
echo '<div class="comments-link">'. genesis_get_custom_field('Comments link text')
.'</div>';
endif;
}

I didn't quite understand how to add code here. Hopefully I did it correctly.

This does output the value text. Now I just need to transform the text into a permalink for that specific blog post. And I will need to do the same for every blog post on my website.

For each blog post, I'm going to enter unique text for the comments link. When clicked, visitors need to be taken to the comments section on the single post page.

I hope that makes sense.

I've pulled together several bits of code, but I just can't seem to weave it together correctly into something that works. Can you please help me with this? Thank you.

ETA: To clarify, the value is not going to be a URL. The value is a short sentence. I'd like the entire sentence to be a link to the comments section on single post page. Thank you.

0

Use make_clickable() function:

add_action( 'genesis_entry_footer', 'custom_comments_field' );
function custom_comments_field() {
    if (  is_single() && genesis_get_custom_field('Comments link text') ) :
        echo '<div class="comments-link">'. make_clickable( genesis_get_custom_field('Comments link text') ) .'</div>';
    endif;
}

UPDATE:

In that case, try this:

add_action( 'genesis_entry_footer', 'custom_comments_field' );
function custom_comments_field() {
    if (  is_single() && genesis_get_custom_field('Comments link text') ) :
        global $post;
        echo '<div class="comments-link"><a href="'. get_permalink( $post->ID ) .'">'. genesis_get_custom_field('Comments link text') .'</a></div>';
    endif;
}
4
  • Thank you, Ashok. If I enter a URL for the value, it automatically becomes a link. So I'm one step closer. But I would like to type a sentence, not a URL, and for that text to be the permalink for that blog post, which takes me to the single post page. I'm not sure how to automatically turn text into a permalink.
    – Carla
    Nov 24 '14 at 7:55
  • I have edited the comment @Carla Nov 24 '14 at 8:05
  • I was happy to learn about 'make_clickable' from you, and now you've been an even bigger help. This works perfectly. Studying your code, I now see where I went wrong. Thank you so much!!
    – Carla
    Nov 24 '14 at 16:02
  • @Carla If it worked for you, would you please mark it as correct answer? :) Nov 24 '14 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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