如何用自定义 BBCode 标签替换 HTML 标签?
How to replace HTML tags by custom BBCode tags?
我正在创建一个没有任何 CMS 的博客系统。
是否可以为博客的 HTML 标签创建自定义替换,例如:<img src="linktopic">
到 [img="linktopic"]
.
如果 <iframe>
和 <a>
标签可能相同。
这是一个 wordpress 简码的例子:https://codex.wordpress.org/Shortcode_API
创建短代码的一个简单示例是转到您网站的主题文件夹并将以下代码添加到您的 functions.php 文件中:
//[foobar]
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
所以当你在后端使用 [foobar] 时,前端会显示 "foo and bar" 文本。
如果您使用的是 wordpress,则可以创建自定义短代码。您可以在此处找到教程:https://www.elegantthemes.com/blog/tips-tricks/how-to-create-shortcodes-in-wordpress
这里还有一个简码生成器:https://generatewp.com/shortcodes/
如果你想在 Wordpress 之外使用短代码
这是可能的。有一个 composer 包,允许您在任何 PHP 应用程序中创建类似 wordpress 的简码:https://github.com/maiorano84/shortcodes
您可以在这里找到教程:https://www.codediesel.com/php/adding-wordpress-like-shortcodes-to-your-web-applications/
我正在创建一个没有任何 CMS 的博客系统。
是否可以为博客的 HTML 标签创建自定义替换,例如:<img src="linktopic">
到 [img="linktopic"]
.
如果 <iframe>
和 <a>
标签可能相同。
这是一个 wordpress 简码的例子:https://codex.wordpress.org/Shortcode_API
创建短代码的一个简单示例是转到您网站的主题文件夹并将以下代码添加到您的 functions.php 文件中:
//[foobar]
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
所以当你在后端使用 [foobar] 时,前端会显示 "foo and bar" 文本。
如果您使用的是 wordpress,则可以创建自定义短代码。您可以在此处找到教程:https://www.elegantthemes.com/blog/tips-tricks/how-to-create-shortcodes-in-wordpress
这里还有一个简码生成器:https://generatewp.com/shortcodes/
如果你想在 Wordpress 之外使用短代码
这是可能的。有一个 composer 包,允许您在任何 PHP 应用程序中创建类似 wordpress 的简码:https://github.com/maiorano84/shortcodes
您可以在这里找到教程:https://www.codediesel.com/php/adding-wordpress-like-shortcodes-to-your-web-applications/