• Resolved Zarul

    (@fariszarif)


    Hi, i want to display list of link that consist with title. when we click on title will go to that page.

    but when i use the <a href=”my_link”>TITLE</a> always come as string as the code is set to esc_html.

    Please help me

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Zarul

    (@fariszarif)

    is there anyone can help me??

    Al-Amin

    (@alamin56649)

    Hello @fariszarif,

    Thank you for reaching out.

    You can create a custom function that outputs the links without escaping the HTML. Here is a basic example of how you might generate the links with a custom shortcode function. Add the following code to your theme’s functions.php file or a custom code snippet plugin:

    function directorist_listings_shortcode() {
        $args = array(
            'post_type' => 'at_biz_dir',
            'posts_per_page' => -1,
        );
    
        $query = new WP_Query($args);
        $output = '';
    
        if ($query->have_posts()) {
            $output .= '<ul>';
            while ($query->have_posts()) {
                $query->the_post();
                $post_title = get_the_title();
                $post_link = get_permalink();
                $output .= '<li><a href="' . esc_url($post_link) . '">' . esc_html($post_title) . '</a></li>';
            }
            $output .= '</ul>';
        } else {
            $output .= 'No posts found.';
        }
    
        wp_reset_postdata();
        return $output;
    }
    add_shortcode('directorist_listings_link_with_title', 'directorist_listings_shortcode');
    

    Then, you can use [directorist_listings_link_with_title] shortcode in any post or page to display the list of links.

    Feel free to let us know if you have any questions or require additional assistance.

    Regards,
    Al-Amin Khan
    Directorist Support Team.

    Thread Starter Zarul

    (@fariszarif)

    Thank You @alamin56649. The code works. But sorry for confusion, what I want is to esc_html on one of the textarea field for Listing form to display link on single page.

    example = https://prnt.sc/OrnjGYVwRUWe

    • This reply was modified 10 months ago by Zarul.
    • This reply was modified 10 months ago by Zarul.
    Al-Amin

    (@alamin56649)

    Hello @fariszarif,

    Thank you for the update and sorry for any confusion caused.

    To escape the HTML for the textarea field, go to plugins/directorist/templates/single/custom-fields/textarea.php and remove nl2br() and esc_textarea() on line 18 before echoing the value. Here’s a screenshot for reference: Screenshot.

    Please let me know if this works for you.

    Regards,

    Thread Starter Zarul

    (@fariszarif)

    Hi @alamin56649, Thank you for your hard work. the edit work, but I got two questions ;

    1. is it possible to have two text area selection, one is textarea without escape html, one is textarea with escape html
    2. do this code can works if we put in templates instead, so if got any update, we do not need to change the code back.

    Thank You.

    • This reply was modified 10 months ago by Zarul.

    Hi Zarul,

    Thank you for your kind words.

    1. Implementing two text areas, one without HTML escaping and one with HTML escaping, is possible but requires custom development.
    2. Modifying the code to be placed within templates to avoid reapplying changes after updates is also possible.

    I would recommend you to contact with Directorist technical support channel for appropriate guidelines in this regard.

    Best regards,
    Al-Amin Khan

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Want display list of link with title’ is closed to new replies.