How to escape multiline wordpress shortcode?
[accordion_item title="Item 2"]
item content
[/accordion_item]
We could use double brakets, but "/" sign brokes everything. Can't belive WP guys lost this case (
[[accordion_item title="Item 3"]]
item content
[[accordion_item]]
this works, but code below doesn't escaped properly
[[accordion_item title="Item 3"]]
item content
[[/accordion_item]]
Don't want to replace manually brakets with html codes. (and WP automatically get them back after user switch editor mode to visual)
Thanks in advance.
Function get_shortcode_regex() in shortcodes.php makes all logic with escaping shortcodes parsing (capture group 1 and 5)
For example with
[[new_something my_attr="test"]And have content!! [vc_tabs][/vc_tabs][/new_something]]
After preg_match_all you will get that
first capture group is not empty and it is "[" (so you can know that this shortcode is not for rendering)
second capture group will show shortcode name "new_something"
third capture group will show everything in attributes " my_attr="test""
four capture group will show content And have content!! [vc_tabs][/vc_tabs]
Five capture group will show that escape characters has at end.
Basically this means that all information is known when you write escape like this: [[your_shortcode]content[/your_shortcode]]
the Answer: replacing [ by [ and ] by ]
Link: https://wordpress.stackexchange.com/questions/33960/how-do-i-escape-a-in-a-short-code
Side Note:
Wysiwyg <=> text transition causing html encoding is, and always be a problem. I would recommend just getting rig of the visual editor all together!
Related
I'm working on some interesting APIs that have a "?" in their path, like so:
/api/?other/stuff/here
However, if I type "?" in the request URL in Paw, it automatically moves my cursor into the query parameter fields. Is there a way to disable this? I'm forced to use postman at the moment to work around this, which is less than ideal.
Nevermind, using %3F instead fixed the issue
As mentioned before, using %3F should work nicely!
Another, more generic way is to use the URL-Encode dynamic value:
Right-click on the field where you want to insert the special character and pick Encoding > URL-Encoding > Encode
A popup opens and you can type your special character (here ?) in the Input field. You should see the preview of the encoded value at the bottom of the popup.
Continue to type the end of the URL after this dynamic value. And you should be good to go!
I have a WordPress site with a form that people can fill out. The data is put into the database and used to create a simple one-page website. If the user wants to edit the website, the data is pulled out of the database and used to pre-populate the original form, where the user can change what they want and resubmit the form. The problem is that if the text entered into the form contains an apostrophe, as in "You'll love this product" when the text is read from the database and put into the value attribute for the input element, it displays in the form as "You\'ll love this product." An if that is submitted, the next time it comes back out of the database and into the form it's "You\\\'ll love this product.
How should I be handling this form text to keep these "\" escape characters from being generated and displayed?
Have you tried stripslashes(), regarding the line breaks just use the nl2br() function.
Example:
$yourString = "That\'s all\n folks";
$yourString = stripslashes(nl2br($yourString));
echo $yourString;
Note: \ double slashes will turn to \ single slashes
You should probably set-up your own function, something like:
$yourString = "That\'s all\n folks";
function escapeString($string) {
return stripslashes(nl2br($string));
}
echo escapeString($yourString);
When I search on my wordpress site I want to filter the search results, namely, I want to remove the first line of each search result.
However wordpress returns the text with all newlines removed, just a chunk of text, so I can not decipher where the new lines are removed.
I tried overriding the
function wp_trim_excerpt($text)
Function, but the $text passed there already has new lines removed. Can someone point me in the right direction of where/when this happens so I can modify the function?
It's removed because the loop.php will use the_excerpt() for searches and archives by default. Change it to the_content() or create / use your own custom function to return the search results in the format you want it in.
Here's the problem:
I have couple of pages which gets its content from a database. The content is displayed in a Literal control kept on an asp.net page.
The article sometimes gets quite long so I want to break the content into two parts using a client script. Unfortunately I cannot change the query to pull data partially. The entire data has to come.
What I want is that when the page (http://mysite.com/showpage.aspx?pid=45) or any other page is opened, I show the first 500 words in that literal control. A Link gets generated below the 500 words which says 'Click Here to View More...'
On clicking this link, a postback occurs and this time the entire content is shown to the user. I understand there is an extra roundtrip required but that's ok for my users.
How can I create such a functionality? Please help me with the script. Thanks.
i use the following jQuery function to shorten a div of text and add a more button.
http://www.reindel.com/truncate/
Where, in the example below, 120 is the character limit.
Character limit:
An acceptable set of characters
(designated by a regular expression)
to truncate in front of, once the max
has been reached. If an acceptable
character is not found at the max, the
plugin will traverse the string
backwards until one is found. If none
is found, the string will not
truncate. The default value is a
single white space character.
$("#contentDiv").truncate( 120,{
chars: /\s/,
trail: [ " ( <a href='#' class='truncate_show'>more</a> . . . )",
"( . . . <a href='#' class='truncate_hide'>less</a> )" ]
});
Basically you need to have a function to count the number of words including the space and other characters.
If the total is exceeding 500 words, wrap the 500 characters with the hyperlink and take only the first 500 characters.
Alternatively you might want to try any JQuery tooltip.
Hope this helps,
hadi
I am trying to work out the overhead of the ASP.NET auto-naming of server controls. I have a page which contains 7,000 lines of HTML rendered from hundreds of nested ASP.NET controls, many of which have id / name attributes that are hundreds of characters in length.
What I would ideally like is something that would extract every HTML attribute value that begins with "ctl00" into a list. The regex Find function in Notepad++ would be perfect, if only I knew what the regex should be?
As an example, if the HTML is:
<input name="ctl00$Header$Search$Keywords" type="text" maxlength="50" class="search" />
I would like the output to be something like:
name="ctl00$Header$Search$Keywords"
A more advanced search might include the element name as well (e.g. control type):
input|name="ctl00$Header$Search$Keywords"
In order to cope with both Id and Name attributes I will simply rerun the search looking for Id instead of Name (i.e. I don't need something that will search for both at the same time).
The final output will be an excel report that lists the number of server controls on the page, and the length of the name of each, possibly sorted by control type.
Quick and dirty:
Search for
\w+\s*=\s*"ctl00[^"]*"
This will match any text that looks like an attribute, e.g. name="ctl00test" or attr = "ctl00longer text". It will not check whether this really occurs within an HTML tag - that's a little more difficult to do and perhaps unnecessary? It will also not check for escaped quotes within the tag's name. As usual with regexes, the complexity required depends on what exactly you want to match and what your input looks like...
"7000"? "Hundreds"? Dear god.
Since you're just looking at source in a text editor, try this... /(id|name)="ct[^"]*"/
Answering my own question, the easiest way to do this is to use BeautifulSoup, the 'dirty HTML' Python parser whose tagline is:
"You didn't write that awful page. You're just trying to get some data out of it. Right now, you don't really care what HTML is supposed to look like. Neither does this parser."
It works, and it's available from here - http://crummy.com/software/BeautifulSoup
I suggest xpath, as in this question