让WordPress文本小工具支持简码(shortcodes)和PHP代码

前端之家收集整理的这篇文章主要介绍了让WordPress文本小工具支持简码(shortcodes)和PHP代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

wordpress网站制作的过程中,站长朋友们会发现,默认情况下wordpress文本小工具是不支持简码(shortcodes)和PHP代码的。这篇wordpress教程里,我们就向大家介绍一下让wordpress文本小工具支持简码(shortcodes)和PHP代码方法

切换到主题目录,打开 functions.PHP 文件,加入以下代码即可:

Crayon-5c891cc39b53d235210632" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-2">2
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-4">4
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-6">6
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-8">8
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-10">10
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cc39b53d235210632-12">12
Crayon-num" data-line="Crayon-5c891cc39b53d235210632-13">13
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891cc39b53d235210632-1">Crayon-c">//让文本小工具支持简码
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-2">Crayon-e">add_filterCrayon-sy">(Crayon-s">'widget_text'Crayon-sy">,Crayon-h"> Crayon-s">'do_shortcode'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cc39b53d235210632-3">Crayon-c">//让文本小工具支持PHP代码
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-4">Crayon-e">add_filterCrayon-sy">(Crayon-s">'widget_text'Crayon-sy">,Crayon-s">'execute_PHP'Crayon-sy">,Crayon-cn">100Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cc39b53d235210632-5">Crayon-t">functionCrayon-h"> Crayon-e">execute_PHPCrayon-sy">(Crayon-v">$htmlCrayon-sy">)Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-6">Crayon-h"> Crayon-st">ifCrayon-sy">(Crayon-e">strposCrayon-sy">(Crayon-v">$htmlCrayon-sy">,Crayon-s">"<"Crayon-sy">.Crayon-s">"?PHP"Crayon-sy">)Crayon-o">!==Crayon-t">falseCrayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891cc39b53d235210632-7">Crayon-h">Crayon-e">ob_startCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-8">Crayon-h">Crayon-k ">evalCrayon-sy">(Crayon-s">"?"Crayon-sy">.Crayon-s">">"Crayon-sy">.Crayon-v">$htmlCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cc39b53d235210632-9">Crayon-h">Crayon-v">$htmlCrayon-o">=Crayon-e">ob_get_contentsCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-10">Crayon-h">Crayon-e">ob_end_cleanCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cc39b53d235210632-11">Crayon-h"> Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891cc39b53d235210632-12">Crayon-h"> Crayon-k ">returnCrayon-h"> Crayon-v">$htmlCrayon-sy">;
Crayon-line" id="Crayon-5c891cc39b53d235210632-13">Crayon-sy">}

有需要的朋友可以使用上面的代码进行测试。

原文链接:https://www.f2er.com/wordpress/238374.html

猜你在找的wordpress相关文章