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;
}
3
  • Are you trying to append this to all wp posts? Commented Jan 9, 2017 at 16:35
  • no eventaully will just be a specific custom post type that will append to Commented Jan 9, 2017 at 16:38
  • the custom post types will also be password protected so the content with the gallery shouldnt show unless valid password was presented Commented Jan 9, 2017 at 16:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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: stackoverflow.com/questions/28458307/… OR just code a standard php web form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.