Okay
  Public Ticket #3241551
URL Link Field
Closed

Comments

  • Paul Wilson started the conversation

    Hi Team,

    Your documentation doesn't provide any examples of implementation, but I'm just trying to find the best method to use to adjust the table data to remove the link from a URL Link field if no link is provided.

    The data I have in a couple of columns potentially will be a mixture of data with links and just text.

    I want to ensure if a the data uses "link || name" forma, it will render with the link as normal.
    If it doesn't contain "||", then just render the text with no link.

    Thanks

  • Paul Wilson replied

    Hi Team,

    I'm using wpdatatables_filter_link_cell( $formattedValue, $tableId )

    And I can check the formatted value for something specific and return the correct formatted value like this;

    if (str_contains($formattedValue, '/wa-works-tag/')) { return $formattedValue; }

    However, I'm unable to extract the link text using PREG MATCH or PREG MATCH ALL

    preg_match_all('/<a\s[^>]*href="[^"]*"[^>]*>(.*?)<\/a>/', $formattedValue, $matches);
    if (count($matches) > 0) { return $matches[1]; }

    I have verified the regular expression using https://regex101.com

    However, no luck.

    I'm making the assumption that the $formattedValue is the same as the anchor tag that is rendered on screen. Which based upon my initial check to return the $formattedValue unchanged would seem to be a correct assumption.

    Any ideas would be appreciated.

  • Paul Wilson replied

    Hi Team,

    I'm using this filter "wpdatatables_filter_cell_val", and the below code to built the link myself.

    if (str_contains($val, '||')) {
            list($link, $content) = explode('||', $val);
            return "<a data-content='{$content}' href='{$link}' target='_blank'>{$content}</a>";
    }

    return $val;

    However, I think that there should be an option to not show a link on this field if none is present.

    Unless there is an easy way using the other filter I started with?

    Thanks

  •  1,850
    Miloš replied

    Hi, Paul.

    Thanks for reaching out to us.

    -

    I am not very good with hooks and custom solutions like this,

    and additionally, that does not fall under the scope of our support, unfortunately, to achieve this with a hook will take some custom work,  which we are not able to provide currently.

    But i might have an easier idea that you can try to achieve this goal,

    but it would be switching from using an URL type column to a String column.

    -

    For example, there was a user who needed to have some plain text along with hyperlinks in same cell.

    In that situation, of course, we want to separate what should be rendered as a link and the other text just as plain text.

    Here is an example how we did that, this user wanted to have some text on a first line, then have a line break, and add some text with links beneath.

    7888378079.png

    You can use our String type column,

    it can render custom HTML - so,  you will need to format the cells in a certain way.

    If you need multiple lines, then It has to be a 'multi-line string', and the same for the editor type in the Editing setting of that column,

    ( If it is an editable table - if it is not editable, then ignore that part);

    then you can directly input text,  and for links, use HTML anchor tags and <br> for new lines.

    For example, a cell can be formatted like this :

    Auxito 10S <br>
    Buy <a href="https://LinkToAmazon">Amazon</a>
    Buy <a href="https://LinkToDirect">Direct</a>
    Buy <a href="https://LinkToAliExpress">AliExpress</a>

    And if i make this in a table, it will be like this :

    5295483771.png

    6140275930.png

    5142621607.png

    As you see, any content we wrap in HTML anchor tags gets properly rendered as links, while other text is just rendered as plain text.

    Of course, you can add custom CSS to customize the fonts, colors, etc.

    Please check more about customizing cells/columns here.

    -

    Let me know if that helps. Thank you.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables