Optimizely Integration

Posted in: Newsmag
Post count: 15

Hi there,

I installed Optmizely on Newsmag 2 (v2.2.1) and I’m having trouble with the second part of the installation. For Optimizely to work I need to add the post id variable to the headline class. It would look something like this (I pulled this sample from WordPress Codex)

<h1 id="post-<?php the_ID(); ?>" class="optimizely-<?php the_ID(); ?>"><?php the_title(); ?></h1>

The code worked fine with previous theme but making the change to td_module_single_base.php doesn’t seem to work. I keep getting a syntax error.

How do I add the “optimizely-POSTID” class properly to the post’s headline in Newsmag?

  • This topic was modified 10 years by louist.
Post count: 6535

Hi

According with WordPress documentation the_ID() function should be used within the loop so to get the post id you should insert the code in loop file corresponding for the post template used: http://screencast.com/t/Mdxgs9ehfshttp://screencast.com/t/GnBSHIwOZzC The result should be like here: http://screencast.com/t/acOZl7lxK1

Hope this help.
Thanks!

  • This reply was modified 10 years by Andrei L..
Post count: 15

Thanks Andrei,

I actually got it working differently.

I used this code to add the class to the td_module_single_base.php since I thought that’s where the headline was being generated.

Old code in td_module_single_base.php on line 52:

$buffy .= '<h1 class="entry-title">';

Replaced with the line below:

$buffy .= '<h1 class="entry-title optimizely-' . $this->post->ID . '">';

But looking back I think your method seems more efficient. So does the new variable overwrite the old one to avoid having duplicate titles on the post?

Post count: 6535

Hi

By adding the code get_title function from td_module_single_base.php the class will be generated only for the page title tag: http://screencast.com/t/elZ9nAMWB5O The new variable doesn’t overwrite the previous one, it generate another identical class. If you add the code in loop files the class will be generated for entire post content: http://screencast.com/t/OdSwt24GiKxRhttp://screencast.com/t/BmvZ6PcXeg5
If you need that class on headline the best way would be to make the changes in loop files.

Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newsmag’ is closed to new topics and replies.