wordpress 如何在wordpress中插入代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13247984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert code into wordpress
提问by Mihir
In many wordpress blogs, we are seeing the code like below.
在许多 wordpress 博客中,我们看到如下代码。
Now I want to put my code also like this? How to do it? is it belongs to any thrid party tool or is it in built comes with wordpress? When I copy and paste the code into blog it looking ugly. Please give me suggestion to make my blog more readable. Thank you
现在我想把我的代码也这样吗?怎么做?它属于任何第三方工具还是内置于 wordpress 中?当我将代码复制并粘贴到博客中时,它看起来很难看。请给我建议,使我的博客更具可读性。谢谢
回答by HareRam
If you are running your blog on Wordpress.com, you just include the following lines before your code.
如果您在 Wordpress.com 上运行您的博客,您只需在代码前包含以下几行。
[sourcecode language="csharp"]
//your code comes here
[/sourcecode]
Wordpress.com gives us the facility to avoid worrying about code highlighting. If your code is in between these blocks then it will automatically render as per the language you specified. It can support many languages.
Wordpress.com 为我们提供了避免担心代码突出显示的便利。如果您的代码位于这些块之间,那么它将根据您指定的语言自动呈现。它可以支持多种语言。
Some of them are..
他们之中有一些是..
html
html
javascript
javascript
java
爪哇
javafx
javafx
matlab (keywords only)
matlab(仅关键字)
objc
对象
perl
perl
php
php
If you have a self-hosted site, or one hosted on wordpress.org, you should should use the SyntaxHighlighter plugin: wordpress.org/plugins/syntaxhighlighter.
如果你有一个自托管站点,或者一个托管在 wordpress.org 上,你应该使用 SyntaxHighlighter 插件:wordpress.org/plugins/syntaxhighlighter。
This is the plugin the WordPress team sourced to create this functionality on wordpress.com
这是 WordPress 团队为在 wordpress.com 上创建此功能而采购的插件
For more information see this link
有关更多信息,请参阅此链接
回答by SHEKHAR SHETE
Sorry to say, but with following code you mentioned WONT WORK
很抱歉,但使用您提到的以下代码 WONT WORK
[sourcecode language="csharp"]
//your code comes here
[/sourcecode]
So, on Wordpress Siteto add Code snippet to the wordpress blog is:
因此,在Wordpress 站点上向 wordpress 博客添加代码片段是:
[code language="javascript"]
//your language script here
[/code]
Hope this helped you! :)
希望这对你有帮助!:)
回答by CMoreira
What you are looking for is some kind of syntax highlighter. Where the code shows up in your post in a box with the number of lines, etc, correct?
您正在寻找的是某种语法荧光笔。代码在您的帖子中显示在带有行数等的框中的位置是否正确?
There are some plugins in wordpress for that.
wordpress 中有一些插件可以做到这一点。
Check out:
查看:
http://wordpress.org/extend/plugins/syntaxhighlighter/
http://wordpress.org/extend/plugins/syntaxhighlighter/
http://wordpress.org/extend/plugins/crayon-syntax-highlighter/
http://wordpress.org/extend/plugins/crayon-syntax-highlighter/
Hope it helps. Cheers
希望能帮助到你。干杯
回答by dasfdsa
Adding to SHEKHAR SHETE's answer.
添加到 SHEKHAR SHETE 的答案。
For inline code blocks:
对于内联代码块:
Selecting a text and then performing Alt+Shift+x
will make text like:
选择一个文本然后执行Alt+Shift+x
将使文本如下:
THIS is an example
This will actually sorround the text with <code></code>
这实际上会用 <code></code>
Writing text inside `..`
is another way
在里面写文字`..`
是另一种方式
回答by Deepak
Do this if you want to add code in your wordpress post:
如果您想在 wordpress 帖子中添加代码,请执行以下操作:
Switch to Text from HTML in your wordpress editor, then insert
<code>
as starting tag and
</code>
as end tag.
在你的 wordpress 编辑器中从 HTML 切换到文本,然后<code>
作为起始标签和
</code>
结束标签插入
。
This is the only method that works in the latest wordpress at the time I am writing the answer. Have fun!
这是我写答案时在最新的 wordpress 中唯一有效的方法。玩得开心!