I’m currently studying WordPress and want to create a custom Post Type and have copied code from a tutorial that I am following. The code in the tutorial works but when I copy/paste it into custom page template, I get the following error:
“Parse error: syntax error, unexpected T_FUNCTION in
/home/databasename/public_html/wptheme/demo/wp-content/themes/name/albums.php
on line 3”
I have Googled the issue for hours and there are multiple options but the issue is that I am a beginner and don’t know exactly what to change. I know that the problem is on line 3 but that’s it. Shown below is my code that is located in my custom page template. Any help would be greatly appreciated!
<?php
add_action('init', function() { /*this is line 3*/
register_post_type( 'album', array(
'public' => true,
'label' => 'Album',
'labels' => array('add_new_item' => 'Add New Album')
'supports' => array('title', 'editor'),
'taxonomies' => array('post_tag')
));
});
You are running an outdated version of php, i.e. php <5.3, which does not support anonymous functions which are used in this code.
While you could rewrite the code to use a named function, or
create_function
, you should really just update your php installation to a version from this decade. php 5.2 (or even older versions) is not supported anymore, and therefore insecure.Additionally, your code is missing a comma at the end of one of the lines: