Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wordpress Functions.php中添加库短代码_Php_Wordpress - Fatal编程技术网

在Wordpress Functions.php中添加库短代码

在Wordpress Functions.php中添加库短代码,php,wordpress,Php,Wordpress,如何从functions.php代码中向Wordpress中的内容添加库短代码?我在这里使用的数字是为试用而硬编码的,但最终将是动态的。这是我正在尝试的,但似乎不起作用 add_filter( 'the_content', 'wpse6034_the_content' ); function wpse6034_the_content( $content ) { $gallery_shortcode = '[gallery ids="282,283,284"]'; $content

如何从functions.php代码中向Wordpress中的内容添加库短代码?我在这里使用的数字是为试用而硬编码的,但最终将是动态的。这是我正在尝试的,但似乎不起作用

add_filter( 'the_content', 'wpse6034_the_content' );
function wpse6034_the_content( $content )
{
    $gallery_shortcode = '[gallery ids="282,283,284"]';
    $content .= '<p>Hello World!!!!</p>'.$gallery_shortcode;

    return $content;
}
add_filter('the_content','wpse6034_the_content');
函数wpse6034\u\u内容($content)
{
$gallery_shortcode='[gallery id=“282284”];
$content.='你好,世界!!!!

。$gallery\u短码; 返回$content; }
如果您想要附加到所有特定的post类型,请不要在functions.php文件中这样做。WordPress CODEX有一个简单的解决方案。只需修改该特定帖子类型文件的帖子模板,所有操作都将完成

single-{post_type}.php

如果您的自定义帖子类型为“酷车”,语法如下:

在“主题”文件夹中创建一个文件,并将该文件命名为:

single-COOL_CARS.php


现在,您在模板文件中编辑的任何内容都将显示在该特定帖子类型的所有视图中。

您是否尝试将其附加到所有wp帖子中?不,最终将只是附加到自定义帖子类型中的特定自定义帖子类型。自定义帖子类型也将受到密码保护,因此除非有效,否则图库中的内容不应显示如果我在模板中使用密码,如何确保只有当用户为页面/帖子输入有效密码时,图库才会显示?我会在同一模板上使用简单的PHP输入/表单。基本上只是隐藏你的图库,只显示php表单。输入密码后,只需显示表单即可。您可以像我在这里发布的那样使用AJAX:或者只编写一个标准的php web表单。