Home / functions.php / Embed Google books in your posts using shortcode
  • How to Embed Google books in your posts using shortcode


    Adding the first snippet to the functions.php of your wordpress theme will let you use shortcode to embed google books. Just because it took me a while to find the ISBN number to embed a book. Look at the top right of the page when viewing a book for “About This Book”. Click on about this book and at the very bottom of the page you will find the ISBN number.

    You will also notice that some books have multiple ISBN numbers eg: 0578022702, 9780578022703 both should work but grab the first one before the comma. If the book does not have an ISBN number you can get the id from the url. ( example screenshot ) ( click code to copy )

    wordpress snippet : PHP

    add_shortcode('gbooks', 'sc_embed_google_books');
    function sc_embed_google_books( $atts ){
    		"id" => '',
    		"width"  => '600',
    		"height" => '900',
    	), $atts));
    	return '<script type="text/javascript" src="http://books.google.com/books/previewlib.js"></script>
            <script type="text/javascript">
            GBS_insertEmbeddedViewer("'.$id.'", '.$width.','.$height.');
    ( click code to copy )

    wordpress snippet : SHORTCODE

    [gbooks id="0578022702" width="400" height="400"]

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, shortcode_atts, _e, wp,
  • Pingback: WordPress shortcode available for Google Books | ButlerBlog()

  • Gabriel Merovingi

    There is a ” missing for the width.

    Should be:
    [gbooks id=”0578022702″ width=”400″ height=”400″]

  • Andrew Goddard

    This looks a really useful addition for my site but I’m totally new to WP and have not played around with code before.  I have found functions.php in my Graphene 1.4.1 theme and I added the code by using the clipboard button and then pasting it in right at the end and saving the new file.  However, when I then tried to use it by going to new post I got some sort of error code (to do with header and calling something) which stuck with me.  Fortunately I’d pasted the original file into Notepad so I simply repasted it back over the edited file and saved and all now seems to be back to normal but of course I cannot use the shortcode.
    It may be this is a bit too complex for someone new but I wonder if I’m just pasting the code in the wrong place in the file or doing something else that is easily rectified.  Can you advise me at all?

    • If you post the code within the functions.php file on http://pastebin.com/ I can post a revised version with the shortcode added. It may be something within your theme that the code conflicts with.

      • Andrew Goddard

        Thanks.  Just pasted as Goddardfunctions.php  Never used pastebin before but think I’ve done it OK.  One other thought – if my theme is updated I presumably need to reinsert the code so should keep a copy of whatever works.  Thanks for your kind help.  Andrew

        • Hi Andrew ill need the URL to where you pasted the code pastebin creates a random short url for each posting. 

      • Andrew Goddard

        Thanks. Not sure my first attempt to tell you got through.  Looks like it is to be found at  http://pastebin.com/DQtJcd8g

        • Hi Andrew,
          I added the google books shortcode so things should work now,

          just add the shortcode to your post and things should work great,
          [gbooks id=”0578022702″ width=”400″ height=”400″]

          Let me know,

  • Andrew Goddard

    Many thanks.  Much appreciated.  The first fruit of this you can now see at
    Hope I’ve given proper due acknowledgments to you and Chad
    As I get round to developing the site and blog I think I will use this shortcode quite a bit so many thanks.


    • Hi Andrew no problem, glad that I could help. Site is looking great always!

  • Kylie

    Hi, I realize nobody has posted here in a while, but hopefully someone can help.

    I pasted the code in my functions.php and added the shortcode to a page. I added the google book id (no ISBN yet, but want to display a free view on site). Also pasted the id in the function code where it says id=>”
    Nothing shows up on the page, but the shortcode does disappear. Any thoughts? I’m using the Avada theme.

    • Kylie

      So I got it to work with your example book. I’m thinking the problem is that my book is uploaded to “My Books” on Google. It doesn’t have an ISBN yet and is not publicly published yet. Any thoughts on how to get it to work?