Jump to content
Sign in to follow this  
ducksunlimitedcanada

Add different shortcode to header on individual pages?

Recommended Posts

ducksunlimitedcanada

Hi. I have two pages that need a different countdown timer in the header. I have a widget for the timer that works great so i have the shortcodes, but am unsure how to best implement it. I tried looking at the hook idea, but then the timer is hardcoded to one setting whereas I need to be able to change it. Sorry my php skills are truly lacking! Thanks in advance.

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Thanks for the reply. this is where my beginner scripting (all javascript mind you) skills start to fail me! So following the example in functions.php I tried the following...and it didnt work, of course ;)

add_action('pagelines_before_branding', 'add_counter');
	
	// function name
	function add_counter(){
		is_page( 'page-name-here' ){
		[fergcorp_cdt_single date="october 4, 2011"]
				}
	
			 }

what am i doing wrong? and thanks again for the help!

Share this post


Link to post
Share on other sites
catrina
[fergcorp_cdt_single date="october 4, 2011"]
<- The date cannot be formatted this way. It must be
"F jS, Y"

(F = month, jS = day, Y = year) That's possibly part of the problem


Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Changed the date to 10 04, 2011, but the entire site just does not load (admin dashboard and all)...empty pages! hmmm

Share this post


Link to post
Share on other sites
timlinson

`is_page( 'page-name-here' ){` should likely be: `if( is_page( 'page-name-here' ) ){`

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

nope still breaks the entire site. Do i have to initialize the hook somewhere else?

Share this post


Link to post
Share on other sites
timlinson

Did you get it to work without the `is_page` conditional yet? Need to break it down to pinpoint which part is causing the error.

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

as a matter of fact, no! I can get it to display the actual shortcode, say in a div

	add_action('pagelines_before_branding_icons', 'add_counter');
	
	// function name
	function add_counter(){
		?>
			<div>[fergcorp_cdt_single date="october 4, 2011"]</div>
		<?php
			}
but this
	add_action('pagelines_before_branding_icons', 'add_counter');
	
	// function name
	function add_counter(){
	
			[fergcorp_cdt_single date="october 4, 2011"]
	
			}

just breaks the whole thing. I know its something in the function. Do i have to call the shortcode in some other manner? Thanks for all your help!!

Share this post


Link to post
Share on other sites
timlinson

I didn't notice it before. The shortcode isn't php, so you need to put `?>` before and `<?php` after it like the 1st case (even if you don't want a div): ` function add_counter(){ if( is_page( 'PGNM' ) ){ ?> [fergcorp_cdt_single date="october 4, 2011"] <?php } } `

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Ok the conditional is working, but it is just displaying the shortcode written out like this: [fergcorp_cdt_single date="october 4, 2011"], not the actual counter. hmmmm

Share this post


Link to post
Share on other sites
kastelic

Try the do_shortcode() function, without closing the php tags:

	function add_counter(){
	   if( is_page( 'PGNM' ) ){
	      do_shortcode('[fergcorp_cdt_single date="october 4, 2011"]');
	   }
	}
	

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Well thanks to Jimmy, its not breaking the site anymore! But alas its not showing the counter at all. hmmm. could it be the shortcode itself?

Share this post


Link to post
Share on other sites
kastelic

Try adding this line before the do_shortcode() line:

echo "findme";

And see if it appears. Try hitting ctrl-F to search for "findme" and also viewing the source of your page and doing the same thing. If you can't find it, then your conditional tag may be incorrect or your on the wrong page, or you don't have the branding section in place, and if you can find it, then it could be the shortcode is not working.

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Alrighty! Thanks for that. Found "find me". So i guess i will post to the plugin's help, see if i come up with anything. thanks for all your help everyone!

Share this post


Link to post
Share on other sites
ducksunlimitedcanada

Hi Catrina. I have posted a help for the plugin...have yet to hear anything. It seems the do_shortcode() isnt "do"ing anything! If anyone has any other ideas, post away!

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  

×