HTML Stripping
-
I have a very basic need, which I (almost) solved with some very basic html.
The trouble is that when I use this in a product description, the code ends up getting reformated as you see in the link provided.
It should appear as it does on this page (about 1/2 way down)
https://www.coachmansdelight.com/online-learning/live-online-classes/I’ve tried several form plugins to make a similar dialog, but they are all centered on gathering information from the user, rather than providing information. I have not yet found one that just allows this very basic user interface for a simple answer to a common question.
What do you suggest?
The page I need help with: [log in to see the link]
-
Consider making a custom shortcode to output your html. This will bypass the editor filter so you can use whichever tags you need.
So your product description would contain: [my_shortcode_name]
To give it effect, use:
<?php add_shortcode( 'my_shortcode_name', 'my_function' ); function my_function() { ?> <p>my html here</p> <?php } // end functionThis code goes in your child theme’s functions.php or you can use the “My Custom Functions” plugin.
Thanks. This looks like it might help me, but I am getting a syntax error.
Here’s what I pasted, yes, leaving ‘my_shortcode’ and so on, which I figured I’d update with real names once I have it working.
<?php
add_shortcode( ‘my_shortcode_name’, ‘my_function’ );
function my_function() {
?>
<p>
<html>
<body>
Classes are held at 9pm Eastern Time. To see what time the class will be where you are, select your location below.<form>
Select Your Location:
<select id=”mySelect”>
<optgroup label=”United States & Canada”>
<option value=”10:30pm”>Newfoundland Time</option>
<option value=”10pm”>Atlantic Time</option>
<option value=”9pm”>Eastern Time</option>
<option value=”8pm”>Central Time</option>
<option value=”7pm”>Mountain Time</option>
<option value=”6pm”>Pacific Time</option>
</optgroup>
<optgroup label=”Australia”>
<option value=”12pm + 1 day”>Australian Eastern Standard Time</option>
<option value=”1pm + 1 day”>Australian Eastern Daylight Time</option>
<option value=”11:30am + 1 day”>Australian Central Standard Time</option>
<option value=”12:30pm + 1 day”>Australian Central Daylight Time</option>
<option value=”10am + 1 day”>Australian Western Standard Time</option>
</optgroup>
<optgroup label=”New Zealand”>
<option value=”3pm”>New Zealand Daylight Time</option>
<option value=”3:45pm”>Chatham Daylight Time</option>
</optgroup>
<optgroup label=”Europe”>
<option value=”2am + 1 day”>Western European Time</option>
<option value=”3am + 1 day”>Central European Time</option>
<option value=”4am + 1 day”>Eastern European Time</option>
</optgroup>
</select> <button type=”button” onclick=”myFunction()”>Show Time</button> <b id=”demo”></b>
</form><script>
function myFunction() {
var x = document.getElementById(“mySelect”).value;
document.getElementById(“demo”).innerHTML = x;
}
</script></body>
</html></p>
<?php
} // end functionPlease remove the opening and closing html and body tags. It may not be enough to get it working but they’re not right here.
Ya, tried that. Didn’t make a difference.
I suspect I’m in the wrong place, since the syntax error comes up site-wide.
Your code works for me. Where did you put the code? This code goes in your child theme’s functions.php or you can use the “My Custom Functions” plugin.
Wherever, put the whole script, including anything else already in there, here to validate it:
http://phpcodechecker.com/Make sure you are using straight quotes and not smart quotes. It may just be the forum editor but your paste has smart quotes.
I’ll double check the smart quotes.
I’m entering it to Genisis –> Dynamik – Custom Options–> Custom FunctionsOk can’t get it past the code checker or the Custom Functions plugin
OK, I’ve sorted it out on the functions plugin. Thanks for that tip.
Two more questions:
Do the “my function” names have to match the “my shortcode” name?
I’m assuming that I replace: function my_function with: function time_checkSecond;
I added the shortcode on the second line of text in the content, but it shows up in the first line of text.1. Yes.
2. You’ll need to return the html, not print it. The easiest way to do this is to open a buffer, make the output, then return the buffer contents:
function .. ob_start(); ?> <p>etc</p> <?php return ob_get_clean(); }Is that a second function, or something I put into the first function, or the page that I’m adding the shortcode to?
No, yes and no respectively.
add_shortcode( 'my_shortcode_name', 'my_function' ); function my_function() { ob_start(); ?> <p> Classes are held at 9pm Eastern Time. To see what time the class will be where you are, select your location below. <form> Select Your Location: <select id="mySelect"> <optgroup label="United States & Canada"> <option value="10:30pm">Newfoundland Time</option> <option value="10pm">Atlantic Time</option> <option value="9pm">Eastern Time</option> <option value="8pm">Central Time</option> <option value="7pm">Mountain Time</option> <option value="6pm">Pacific Time</option> </optgroup> <optgroup label="Australia"> <option value="12pm + 1 day">Australian Eastern Standard Time</option> <option value="1pm + 1 day">Australian Eastern Daylight Time</option> <option value="11:30am + 1 day">Australian Central Standard Time</option> <option value="12:30pm + 1 day">Australian Central Daylight Time</option> <option value="10am + 1 day">Australian Western Standard Time</option> </optgroup> <optgroup label="New Zealand"> <option value="3pm">New Zealand Daylight Time</option> <option value="3:45pm">Chatham Daylight Time</option> </optgroup> <optgroup label="Europe"> <option value="2am + 1 day">Western European Time</option> <option value="3am + 1 day">Central European Time</option> <option value="4am + 1 day">Eastern European Time</option> </optgroup> </select> <button type="button" onclick="myFunction();">Show Time</button> <b id="demo"></b> </form> <script> function myFunction() { var x = document.getElementById("mySelect").value; document.getElementById("demo").innerHTML = x; } </script> </p> <?php return ob_get_clean(); } // end functionThanks!
The topic ‘HTML Stripping’ is closed to new replies.