How to use ' inside an array?

Asked

Viewed 107 times

1

I’m facing a problem with an adaptation on functions.php of my theme Wordpress.

What happens, I want to put:

':'(' => 'choro.png',

Only it’s not possible by the second '

I tried to use:

':\'(' => 'choro.png',

Only it doesn’t work.

I’m making an adaptation on my smilyes, what should happen is that when a person puts :'( a little crying face appeared, only because the code is :'( conversion does not happen.

I’ve made several adaptations like: :) ;) :( :| all worked well, only :'( doesn’t work.

  • 2

    Why don’t you use ":'(" => 'choro.png', ? That is, quotes to delimit leaving the content free to contain plicas.

  • I tried to use, but it doesn’t work.

  • Define what you mean by "does not work". Gives error, what happens?

  • Simply does not happen to the conversion. Appears in text format, ie, :'(

  • You need to see if WP isn’t leaking some value before you get to this function. Test with other symbols (accented letters, etc) to see if the same problem happens. For example '(á)' => 'teste.png'.

  • It worked normal with your (á)

  • Only if you do it with :'( It doesn’t make the conversion. Ah! I realized that it changes the accent when I comment :'( for :’(

  • Any idea of a solution?

  • Test with ':’(' => 'choro.png' then :)

  • No...... :( :( :( :( Did not work.....

  • If I comment :\’( works. But it has to work with :'(

  • I used it like this: ":’(" => 'choro.png', and worked perfectly when I comment :’(!! Êbaa.. Only if I comment :'( does not convert.

Show 7 more comments

4 answers

7


According to the comments, your code only finds smileys when they use instead of '. I used Wordpress for a while, and I realized that it replaced some characters with others when sending posts, for the following reason: for ordinary users, replacing ' by its curved variation does not imply any difference in functionality, but makes the posts easier to read by the fact that such symbols are usually used to mark quotes or irony. Microsoft Word does the same thing. Try typing some quotes using " in the Word you will see that it "fixes" them to curved quotes to a certain side depending on the context unless you disable the filter in the settings.

In Wordpress, this filter is called wptexturize and changes many characters, replacing them with their curved variants, such as the ' (the source of your problem) and the quotation marks. The problem is that this filter is not applied when writing the post, but when it is saved on the server, so it is really hard to know where the editing comes from.

To disable it, open the file functions.php Wordpress and, before the last ?>, add the following to disable overwriting on all posts that will be created/edited in the future:

remove_filter ('category_description', 'wptexturize');
remove_filter ('list_cats', 'wptexturize');
remove_filter ('comment_author', 'wptexturize');
remove_filter ('comment_text', 'wptexturize');
remove_filter ('the_title', 'wptexturize');
remove_filter ('the_content', 'wptexturize');
remove_filter ('the_excerpt', 'wptexturize');

I should warn, however, that this will not affect posts that have already been created, so you will have to re-edit all your posts and, if necessary, replace all of smileys to ' again. This will make it easier to create more text replacement codes for smileys that use characters that wptexturize modifies.

  • Great! @Bruno, that’s what I wanted. Note 10! And how do I disable only that part of ' that converts to ? In case you can’t say I’ll use your code, but only the part comment_author and comment_text.

  • And this example? http://pastebin.com/HWYGHDc7 Is there any way to modify it ?

  • I just tested your example on functon.php of my theme, and got ball show! Thank you very much...

1

try to add two more bars, as it is likely that the string to be analyzed is with addslashes or Magic Quotes...

<?php
    ':\\\'(' => "choro.png",
?>

0

Use in this way:

<?php
    ":'(" => "choro.png",
?>
  • In theory, this should work, but it seems that Regex that WP applies can’t see the ', nor the and not escaping the simple quote ':\'('

0

Use double quotes as delimiter, and feel free to use single quotes within the value of the same:

<?php
    ":'(" => "choro.png",
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.