• Resolved donahmar

    (@donahmar)


    Hello,
    I am importing a column called productsupportstatus – values are “Supported” or “Not Supported”.

    I successfully used this string to replace “Not Supported” with “Contact Us”.
    [str_replace(“Not Supported”, “Contact Us”, {productsupportstatus[1]})]

    Now I want to add a green icon in front of “Supported” and a blue icon in front of “Contact Us” using my theme’s icon font. I am trying to do this by adding a span in the string above, but it isn’t working. I was going to use CSS to change the colors. WP All Import isn’t allowing me to add a span in the string (inside the content text editor), and I don’t know PHP yet to successfully write a PHP script in the function editor.

    Can someone help? This is what I have for inline PHP & CSS
    [str_replace(“Not Supported”, “<span class=”blue-icon”></span>Contact Us”, {productsupportstatus[1]})]

    [str_replace(“Supported”, “<span class=”green-icon”></span>Supported”, {productsupportstatus[1]})]

    .blue-icon:before {
    content: “\e034”; //this is from Divi’s icon library
    font-size: 64px;
    color: blue;
    font-family: ‘ETmodules’
    }

    .green-icon:before {
    content: “\e034″; //this is from Divi’s icon library
    font-size: 64px;
    color: green;
    font-family: ‘ETmodules’
    }

    This is what I tried in the Function Editor
    <?php
    if($productsupportstatus===’Supported’) {
    ?>
    <span class=”green-icon”></span>
    <?php
    }
    ?>

    <?php
    if($productsupportstatus===’Not Supported’) {
    //maybe this should be the new value of ‘Contact Us’?
    ?>
    <span class=”blue-icon”></span>
    <?php
    }
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • @donahmar my first recommendation is that you really shouldn’t be storing HTML in the status field. There should be frontend/presentation code that adds that elsewhere based on the values. What plugin are you importing data into that has a field called productsupportstatus?

    The other thing is that with the function editor the expectation is that it is taking the input into a function and the function is returning the value. This documentation page gives you some examples of how that works.

    Thread Starter donahmar

    (@donahmar)

    productsupportstatus is a column in the file I am importing — not a field or plugin.
    I am not importing the productsupportstatus as HTML, I am just trying to append a span to the values so it displays an icon.

    However, it sounds like the Function Editor is how I will get it done. Now I have to learn PHP lol. Thanks @tnolte !

    @donahmar inserting the span tag is HTML. Since I don’t have the full picture of what type of post this is creating I can’t provide a better alternative but it just seems like there might be a better way of accomplishing what you are doing. Since I’m on my phone it’s a little bit harder for me to provide you with some code for the function. When I have a chance to get in my computer I can get something written.

    Thread Starter donahmar

    (@donahmar)

    I solved it with the following:

    //in content area

    [setIcon({productsupportstatus[1]})]
    //in Function Editor
    <?php
    	function setIcon($productsupportstatus){
    		$productsupportstatus = str_replace('Not Supported', '<span class="blue-icon"></span> Contact Us',$productsupportstatus);
    		$productsupportstatus = str_replace('Supported', '<span class="green-icon"></span> Supported',$productsupportstatus);
    	return $productsupportstatus;}
    ?>
    Plugin Author WP All Import

    (@wpallimport)

    Thanks for updating us @donahmar – your solution looks good!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Inserting icon before str replace’ is closed to new replies.