我在自定义插件中添加短代码时遇到问题。自定义插件代码为:
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
Plugin Name: ......
Plugin URI: ..........
description:
..........
Version: 1.2
Author: .............
Author URI: ...........
License: GPL2
*/
function sdsdsd_my_shortcode(){
return '9999999999999999';
}
add_action( 'init', 'sdsdsd_add_shortcode' );
function sdsdsd_add_shortcode() {
add_shortcode( 'sdsdsd_my_shortcode', 'sdsdsd_my_shortcode' )
}在WP管理编辑帖子中:[sdsdsd_my_shortcode],但不是内容,它精确地呈现[sdsdsd_my_shortcode]
插件在可湿性粉剂管理/插件中注册和激活。
相同的代码在子主题中的functions.php中运行良好。该插件是plugins/my-custom-plugin/my-custom-plugin.php
在插件文件中,如果没有add_action( 'init',...,它将无法工作
发布于 2020-06-20 19:41:20
试试这个--
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}
if ( ! class_exists( 'Class_Name' ) ) {
class Class_Name{
public function __construct() {
$this->register_hooks();
}
function register_hooks() {
add_shortcode( 'sdsdsd_my_shortcode', array($this, 'sdsdsd_shortcode_content') );
}
function sdsdsd_shortcode_content() {
ob_start();
//Content
<?php
$form = ob_get_contents();
ob_clean();
return $form;
}
}
return new Class_Name();
}https://stackoverflow.com/questions/62481545
复制相似问题