short code got changed in visual mode in wordpress - php

I am inserting a php short code for widget in wordpress page in text mode. But when i go to visual mode and then again to text mode then my short code converts into comments.
Eg: This is my short code :
<?php dynamic_sidebar('footer-sidebar-4'); ?>
and it converts into:
< !--?php dynamic_sidebar('footer-sidebar-4'); ?-- >
after this my short code does not work.
Please get me through out this problem.

<!-- HTML Comments Go Here --> in HTML. PHP executes before it's HTML on the Client. Your sidebar code should be within PHP tags like: <?php dynamic_sidebar('footer-sidebar-4'); ?>. Notice that your code is not PHP at all, since you don't have the tags right. You just have a useless HTML comment.
Get rid of that comment altogether.
<ul id='sidebar'>
<?php dynamic_sidebar('footer-sidebar-4'); ?>
</ul>
The documentation was very clear: http://codex.wordpress.org/Function_Reference/dynamic_sidebar

Related

How to keep PHP opening and closing tags in ckeditor source as html entity?

In ckeditor, I'm sharing code snippets such as php, html, etc. So for example I would share this:
<?php
//Something here...
?>
Which appears in source view as this:
<?php
//Something here...
?>
When I save it to mysql, the code stays as it should. But when I load up the code, ckeditor changes the code in source view to:
<!--?php
//Something here...
?-->
Are there any solutions to fix this?
You must type your php codes in source view otherwise it's become html code
and for protect it from ckeditor use this code in your config.js file:
config.protectedSource.push(/<\?[\s\S]*?\?>/g);
I added config.protectedSource as Kiyan noted and that works for working within the editor. However to view the page as an article including whatever you added in php I had to add the following in my output article/page:
textarea is the field stored in the mysql database.
<?php echo eval('?>' . utf8_encode($row['textarea']) . '<?php '); ?>
In the editor if I added some php like <?php include ("whatever.php"); ?>, it nicely includes the whatever.php file.

PHP inspection reports CSS selector unused. It is used by a PHP echoed Tag

I have PHP code which creates an HTML
echo('<div id="keyboard">');
In my CSS I have
#keyboard {
}
PHPStorm reports the CSS selector is not used. It is used. Can I make it realize that? In not, I once saw some way of disabling a single error or warning, but I can no longer find that in the documentation.
What you can try is to move the html out of the php script and just open the parentheses when needed. I suspect that the IDE cannot distiguish between php echoed html and html outside of php tags.
<?php
//add php code here
?>
<div id="keyboard">
<?php
//php code here
?>
</div>
<?php
//add php code here
?>
The IDE should now be able to match the CSS with the relavant id.

Wordpress disable code editor formatting for a page

So I have a wordpress page where I need to paste a block of html code, but when I output using the_content() you know that wp wraps things in <p> and so on, so I want for THAT PAGE to echo out the exact code that I paste in the editor without that auto formmating, is there a function or something, I've searched and found wpautopbut doesn't work.
You can switch from the WYSIWYG-View to the HTML-View by clicking the tab at top right corner of the editor window.
There you can inset your raw code surrounded by <pre> </pre> tags.
If you mean you want code that will execute, and not be seen, then you might try stampede design's solution.
There is also a raw HTML plugin that might help.

How do HTML comments work with PHP code?

I just wonder how does html comment tag work with php code.
If I have the following code, does php parse it anyway?
<!--
<?php
echo "hi";
?>
-->
a simple question, but I guess it is important to know.
Oh yes, anything in PHP blocks gets executed, but in this case, it isn't shown to the end user because it's in HTML comments.
In the source of the page that is generated by this PHP script, you will see the output surrounded by HTML comments, simple as that.
The only way comments will affect the output of a PHP script is with valid PHP comments.
Yes it does. If that is between <?php ?> tags
You can use PHP comments /* commment */ and they won't execute.
As a side note to the answers above: You can also interrupt the HTML comment:
<!--
<?php
echo "-->This will be seen!<!--";
?>
-->
gives this output:
<!--
-->This will be seen!<!---->

have this php query also show an html link

can this code snippet be modified to reveal html coding?
<?php $_option = $this->getOption() ?>
<?php echo $this->htmlEscape($_option->getTitle()) ?>
it is showing a title but in that title i have an href:
link
instead of it appearing as a link it just shows me the code.
i'd like it to be a clickable link.
possible?
Yes, just remove the $this->htmlEscape() and leave the $_option->getTitle()
The escape function is to provide just the functionality of not being able to use (or inject) html commands or javascript.

Categories