The DOM is a fancy way of referring to all of the HTML elements on the page. Because the app titles haven’t been loaded yet, the script can’t find them and so it doesn’t work. I fixed the script by wrapping it in document.ready()
, which tells the script not to start processing until the entire document has been loaded. You could use the modified script I posted in my previous post and it would work without having to move the script to the footer.
As for the child theme, the Codex page I linked to is pretty self-explanatory. At the bare minimum, you need a style.css in your child theme’s folder with the following code:
/*
Theme Name: iApp Child
Template: iapp
*/
And in your functions.php
:
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_head', 'custom_js' );
function custom_js() { ?>
<script>
jQuery( document ).ready( function() {
jQuery( '.apptitle' ).each( function() {
if ( jQuery( this ).html().indexOf( '-' ) !== -1 ) {
var s = jQuery( this ).html();
jQuery( this ).html( s.replace( /-/g, ' ' ) );
}
} );
} );
</script>
<?php } ?>
The first part of that file is the code that loads your parent theme’s stylesheet. The second part is the script we’ve been talking about.