Jotting down stuffs
Fixing the Mystique theme Twitter settings issue
I am using the Mystique theme for this WordPress blog. It is a nice theme, however there is an issue that needs fixing – The Twitter widget in the default theme layout somehow defaults to WordPress’s Twitter account, and there’s no setting for that. The Twitter username is hardcoded into the theme code.
In this article, I will post the changes I did to the original theme in order to fix the Twitter issue. At the end of the article, I will provide a link to a zip file which you can download, extract to the Mystique’s theme directory and overwrite the original theme files.
Before that, disclaimers:
- I am not a WordPress expert. This is my first time hacking away a WordPress theme. I mostly did quick tries-n-errors when implementing this hack.
- This hack is not in any way endorsed by the original creator of the Mystique theme.
With that said, use this hack at your own risk. I will appreciate any feedback if you do try out this hack.
Adding a Twitter tab to the Mystique settings
I added a new tab for the Mystique settings. Take a look at the following screenshot to see how it looks like:

Under that tab, you can set your own Twitter username to be used instead of the default WordPress’s.
The following code changes were made to lib/admin.php:
if (isset($_POST['head_code'])): $options['head_code'] = stripslashes($_POST['head_code']); endif; if (isset($_POST['twitter_username'])): $options['twitter_username'] = stripslashes($_POST['twitter_username']); endif; // Hacked by Amry for ($i=1; $i<=6; $i++)
<li><a href='#tab-8'><?php _e("User CSS","mystique"); ?></a></li>
<li><a href='#tab-9'><?php _e("Twitter","mystique"); ?></a></li><!-- Hacked by Amry -->
</ul>
<!-- Hacked by Amry -->
<div id="tab-9">
<table style="width: auto">
<tr>
<th scope="row"><p><?php _e("Twitter Username","mystique"); ?></p></th>
<td><input name="twitter_username" id="opt_twitter_username" type="text" value="<?php $twitter_username = wp_specialchars(get_mystique_option('twitter_username')); echo $twitter_username != '' ? $twitter_username : 'wordpress'; ?>" /></td>
</tr>
<tr>
<th scope="row"></th>
<td>
<h3><?php _e("What does this do?","mystique"); ?></h3>
<ul style="list-style: disc">
<li><em><?php printf(__('link the Twitter settings in the default layout to your own account','mystique')); ?></em></li>
<li><em><?php printf(__('this is hacked by <a href="http://ShamsulAmry.com/blog/fixing-mystique-theme-twitter-issue">Amry</a> and is not supported by the original theme creator, use at your own risk','mystique')); ?></em></li>
</ul>
</td>
</tr>
</table>
</div>
</div>
<!-- /sections -->
Fixing the Twitter widget in the sidebar
The original theme hardcoded the Twitter username to always use “wordpress”. I changed it a bit so that it reads from the saved setting in the previous step.
The following code changes were made to sidebar.php:
<?php if(function_exists('the_widget')): // only in wp 2.8+
the_widget('SidebarTabsWidget', array('orderby' => 'name', 'postcount' => true, 'showcategories' => true, 'showtags' => true, 'showarchives' => true, 'showpopular' => true, 'showrecentcomm' => true), array('widget_id'=>'instance-sidebartabswidget','before_widget' => '<li><div>','after_widget' => '</div></li>','before_title' => '<h3><span>','after_title' => '</span></h3><div></div><div></div>'));
// Hacked by Amry
$twitter_username = wp_specialchars(get_mystique_option('twitter_username'));
if ($twitter_username == '') $twitter_username = 'wordpress';
the_widget('TwitterWidget', array('title'=>__('My latest tweets','mystique'), 'twituser'=>$twitter_username, 'twitcount'=>'4'), array('widget_id'=>'instance-twitterwidget','before_widget' => '<li><div>','after_widget' => '</div></li>','before_title' => '<h3><span>','after_title' => '</span></h3><div></div><div></div>'));
the_widget('LoginWidget', array(), array('widget_id'=>'instance-loginwidget','before_widget' => '<li><div>','after_widget' => '</div></li>','before_title' => '<h3><span>','after_title' => '</span></h3><div></div><div></div>'));
endif; ?>
Fixing the Twitter account linked from the header
The original code in the theme was somehow reading the Twitter username from some setting. Nevertheless, I commented that out and replaced it so that it reads from the saved setting that I had just created.
The following code changes were made to header.php:
<?php
//$twituser = get_mystique_option('twitter_id');
// if(is_active_widget('TwitterWidget'))
// Hacked by Amry
//$twitinfo = get_option('mystique-twitter');
//$twituser = $twitinfo['last_twitter_id'];
$twituser = wp_specialchars(get_mystique_option('twitter_username'));
if ($twituser == '') $twituser = 'wordpress';
if ($twituser): ?>
<a href="http://www.twitter.com/<?php echo $twituser; ?>" title="<?php _e("Follow me on Twitter!","mystique"); ?>"><span><?php _e("Follow me on Twitter!","mystique"); ?></span></a>
<?php endif; ?>
Download the changed files
Click to download: Mystique-Twitter-fix.zip. This zip file contains lib/header.php, sidebar.php and header.php. Simply overwrite the original theme files with these to implement the changes. It would be a good practice to back up the original files before overwriting it in case you need to revert back.
Hope this helps!
| Print article | This entry was posted by Amry on January 31, 2010 at 1:51 am, and is filed under Coding. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 6 months ago
visitting… cool gila!
about 6 months ago
dah berblog bro kita ni hehe….
about 6 months ago
misi ke arah world domination
about 6 months ago
thanks, but bro I did as you said, replace the files in the them but, i still get the same problem with twitter, it shows / in the first tweet and R in the second and the n shows the other tweets normally
about 6 months ago
it worked bro thanks
about 6 months ago
Awesome hack, i will try it on my mystique blog soon!
about 6 months ago
Thx, it litterally kicks ass !
about 6 months ago
I’m using Mystique and I didn’t have to do any of that, it automatically defaults to my twitter account now. All i had to do was add the widget, added my user name for twitter, saved, remove the widget so the mystique theme would just display the default widgets and that’s all.
about 6 months ago
Good that it worked for you. Haven’t tested your method, but I guess it should work seeing from the original header code, it was reading some existing settings.
about 4 months ago
hi what ver of wordpress are this working on
about 4 months ago
It’s working on WP 2.9.2