• 0
Sign in to follow this  
Followers 0

Error using hooks

Question

Posted · Report post

I've been following your base child theme video. I keep getting this error message:

Parse error: syntax error, unexpected ':' in /home/content/12/7237912/html/wp-content/themes/platformbase/functions.php on line 27
Which is produced by this code:
// add_action('hook_name','function name');
		add_action('pagelines_inside_top_branding', 'custom_section');
	
	       // function name
		function new_search(){
	
		get_search_form();
	
		}
		// end function

I've had to re-upload my functions file several times. What am I doing wrong?

Share this post


Link to post
Share on other sites

10 answers to this question

  • 0

Posted · Report post

Let's see more of the surrounding code too. Marking for developer review. Thanks, Bryan

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

It's the original functions.php file. I attempted to copy the video tutorial and got the error message. I've tried it on three different occasions and gotten similar error messages (always some type of "unanticipated character" and then I had to replace the functions file on my hosting site to get it to work. I'm new to PageLines so I followed the directions closely.

<?php
	
	// Setup  -- Probably want to keep this stuff...
		// Set up action for section registration...
		add_action('pagelines_register_sections', 'base_sections');
	
		/* Hello! First, lets load the PageLines core so we have access to the functions */
		require_once(TEMPLATEPATH . "/core/core.init.php");
	
	// ====================================================
	// = BASE FUNCTIONS - Where you should add your code  =
	// ====================================================
	
	 // Hooks are a way to easily add custom functions and content to the Platform theme. There are hooks placed strategically throughout the theme
	 // so that you insert code and content with ease.
	
	 // Below is an example of how you would add a social media icon to the icons in header (branding section)
	 // We have placed a hook at the end of the icon set specifically add new icons without modifying code or having to worry about your edits
	 // getting thrown out during the upgrade process. The way to use hooks goes a little like this:
	
		// add_action('hook_name','function name');
		add_action('pagelines_branding_icons_end', 'add_icons_to_branding');
	
		// function name
		function add_icons_to_branding(){
	
		// what the function does??“in this case adds a stumbleupon icon to the header of your theme. The class referenced in the link can be seen in the style.css
		// and is the image from the CSS is placed in the images folder
			?>
			
	<?php }
		// end function
	
	 // A full list of hooks can be seen by toggling the "advanced" button on each section in the "template setup" option tab. Each hook listed is associated with the section that it is listed under. That's all! Start adding hooks below.
	
	/*
		Register a Drag&Drop HTML Section for the admin.
		A pullquote section was created here for demonstration purposes
	
		Sections should be named: section.[your section name].php and placed in the sections folder.
	
	*/
	function base_sections(){
	
	/*
		Your custom sections get registered in here...
		PageLines Register Section Arguments:
			1. Section Class Name,
			2. Directory name (or filename if in root of 'sections' folder),
			3. Init Filename (if different from directory name),
			4. Section setup and variable array
	*/
	
		pagelines_register_section('BasePullQuote', 'pullquote', null, array('child' => true) );
		pagelines_register_section('BaseSidebar','sb_base', null, array('child' => true) );
	
	}
	
		[/code]

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hi Nancy - I don't see an ending PHP tag, but I'm sure that's probably just a copy/paste thing. Other than that, generally with these types of errors we're looking for missing brackets or missing PHP tags. The only colon (":") that I saw in your code that could be causing the issue is in this line:

// getting thrown out during the upgrade process. The way to use hooks goes a little like this:

Make sure that text is all appearing on the same line, and there are no line breaks in there.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

If the code (as written) is working now, why would it fail when I change only the section mentioned in the first forum post above - per the directions on the tutorial? If I try again, can I test your idea by taking that sentence out completely? I really want to take advantage of hooks but the problem has reoccurred three times.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Okay, I'll have a developer look into this for you. Thanks, Bryan

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hey Nancy, What is the error you're getting?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I'm new at this so I tried to make the changes to functions.php by following the video tutorial. It throws random errors, but here's the most recent:

Parse error: syntax error, unexpected ':' in /home/content/12/7237912/html/wp-content/themes/platformbase/functions.php on line 27
Since I can't tell what to fix, I have to reload the functions.php file to by host. (What editor is used in the video that includes page numbers? That would be helpful.)

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Looks like you have a syntax error in your code... meaning you've placed some code incorrectly. Can you see if there are any colons in your code that might cause this issue? Any unclosed php tags or brackets? Textmate is the text editor... its a Mac program.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I finally got it. Thanks. I'm a hobby user (not a professional) and I love your theme. Please add more examples and problem-solving tips on how to use hooks. Example: Make the editor searchable and include line numbers OR explain how to use an external editor. Example: Explain where "get_new_search" came from. Is there a list of available functions like there's a list of available hook positions? Again - I love your theme and have appreciated the quick responses on the forum.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

In the original code you used above the function name was different from where it was defined in the add_action statement...it should be something like: ` add_action('pagelines_inside_top_branding', 'new_search'); function new_search(){ get_search_form(); } `

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0