Minor changes to parent theme

The parent theme of this site (Datse Multimedia Base) has had some minor updates made to it.  I was just really wanting to do some work on the site, and that was somewhere that I felt that I was able to move forward with site development.

Changes to the footer

I noticed at one point that the footer for this theme (both the parent and the child) were set so that they displayed that they are “Thematic Theme Framework” and I wanted to change that.  There were basically two ways I could change it:

  1. Change the settings which are available through the Theme Options
  2. Change the way that the theme handled those settings which were currently set in the Theme Options

Looking at what was currently set in the Theme Options, I decided that even though it may be quite a bit more difficult to figure out how to fix those than it is to simply change them in the Theme Options I would actually look at seeing how to change the theme itself, so that the shortcode which was being used, actually was displaying the correct information.

Finding where things are set

I knew that this was being set somewhere in the theme itself.  I am not quite sure what the exact procedure I went through was but between looking at the Theme Options, and looking for the actual information that ended up being displayed I went through the following steps:

  • Look at how things are in the Theme Options
    • Find out that there is a shortcode being used
  • Look in the source code for the term Thematic and find where the shortcodes are being set
    • Find the code with grep
    • dig deeper into the theme hierarchy to find where the shortcodes are being set

I ended up finding that the code I wanted to work on was in the theme directory library/extensions/shortcodes.php.

Fixing the issues with how it was being done

I really had no idea how to do this.  I looked to see if there might be some way which works to get the theme information from WordPress itself.  That was if WordPress would give me an existing function which would allow that information to be gathered and then presented.

I found the function wp_get_theme() would return the theme information in an object that I could then get the each bit of information from.

This ended up being pretty simple in logic, but after having made a number of mistakes related to not paying attention closely enough to things.  I ended up creating 8 versions of the theme prior to the current theme release.

These were being released somewhat live.  Well, very live.  I was ending up with some of the variations creating bugs which made major changes to the way that things would get displayed, and even totally breaking the way that things got displayed.


/**
* Display link to Thematic.
*/
function thematic_shortcode_framework_link( $atts ) {

    $a = shortcode_atts ( array(
        'parent' => 'true'
    ), $atts);

    $my_theme = wp_get_theme();
    $theme_name = $my_theme->get("Name");
    $theme_uri = $my_theme->get("ThemeURI");
    $themelink = '<a class="theme-link" title="'.$theme_name.'" href="'.$theme_uri.'" rel="home">'.$theme_name.'</a> theme';
    if (isset($a['parent']) && $a['parent']=='true' && $theme_parent = $my_theme->parent()) {
        $parent_name = $theme_parent->get("Name");
        $parent_uri = $theme_parent->get("ThemeURI");
        $themelink .= ' a child theme of <a class="theme-link" title="'.$parent_name.'" href="'.$parent_uri.'" rel="home">'.$parent_name.'</a>';
    }
    return apply_filters('thematic_theme_link',$themelink);
}
add_shortcode('theme-link', 'thematic_shortcode_framework_link');

This is what the current code for this one shortcode is looking like. Initially it was:


/**
 * Display link to Thematic.
 */
function thematic_shortcode_framework_link() {
    $themelink = '<a class="theme-link" title="Thematic Theme Framework" href="http://thematictheme.com" rel="home">Thematic Theme Framework</a>';
    return apply_filters('thematic_theme_link',$themelink);
}
add_shortcode('theme-link', 'thematic_shortcode_framework_link');

As you can see, while the code is much simpler and almost certainly executes way faster with the version which existed before, the new version actually gives a great deal of other functionality which the old version didn’t.

In fact, the old version, probably has issues with “performance” with it. This was a bit of static code which would be inserted with the simple shortcode theme-link. The problem with that, is if we are simply inserting static text, it probably should not be getting called by the shortcode interface, but rather it should be set as simple static text in some location.

There is a footer text setting which would be a great place for that static text to be placed in a nice fashion. Put it right in there. While my code takes longer to run, there is a reason it is a shortcode, rather than simply as static text. It is using functions which are provided by WordPress to get the Theme Name, and the Theme URI for the current theme.

This means that if anyone changes these values in the theme’s style.css, they automatically get changed with the calling of this shortcode.

Another feature that this gives you, is that a child theme can set the Theme Name and Theme URI in the child theme style.css and with that it automatically gets updated.

A feature that I wasn’t really thinking about too much when I wanted to update this, was that I am actually able to get both information about a child theme (if it is a child theme) and the parent theme.  When I found that out, I thought that with that possibility, I will work on making sure that I display both bits of information, especially since the parent theme can be as, if not more important than the child theme.

Of course when I thought of that, I started to think about how to make this little “link” better display, or more carefully displayed.  I have only done one of the few things which I want to do with this.  Currently I am only looking at turning on and off the display of the parent theme information.  I would like to have people who would want the parent, but not the child theme information displayed.  And I also want to have it set so that I can add, or remove the word theme in the display.

That is all down the road.

This entry was posted in Site News, Themes and tagged , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. Jigme Datse Yli-Rasku
    Posted 2016 October 3 at 23:34 | Permalink

    Updated this. Some stuff I hadn’t realized was getting interpreted as HTML tags, was, and it was messing some stuff up. That’s been fixed (as best I can tell). Also, I noticed that I haven’t got the correct link in the “base theme”. That’s something I need to update in the theme itself. Not tonight…