0

How can I add a gallery shortcode to the content in Wordpress from within my functions.php code? The numbers I'm using here are hard-coded for trial but will eventually be dynamic. Here is what I'm trying but doesn't seem to work.

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;
}
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
user520300
  • 1,497
  • 5
  • 24
  • 46

1 Answers1

0

If you are wanting to append to all of one particular post type then do not do that in the functions.php file. WordPress CODEX has an easy solution. Just modify the POST TEMPLATE for that particular post type file and all will be done.

https://codex.wordpress.org/Post_Type_Templates single-{post_type}.php

If your custom post type is COOL_CARS Syntax is this:

in your themes folder make a file and call the file this:

single-COOL_CARS.php

and now anything you edit in the template file will display for all views of that particular post type.

  • If i do it in the template how to I ensure that the gallery only shows when a user enters a valid password for the page/post? – user520300 Jan 09 '17 at 17:21
  • I would do a simple PHP input / form on that same template. Basically just hide your gallery and only show php form. on password input then just show the form. You can use AJAX like I have posted here: http://stackoverflow.com/questions/28458307/how-to-pass-multiple-variables-to-php-with-jquery OR just code a standard php web form. – technology101010 Jan 10 '17 at 17:37