Support » Fixing WordPress » embeding audio only in the homepage

  • Hello to all. I understand by this thread located here, I am to use the embed tag. I know how to do it but I only want it on the home page and not every ware else on the site. How can I only get it on the home page and where would I put the embed tag since there technically no head section as I’m dealing with php scripts and plugins to run the site.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Josh

    (@josh401)

    Moderator and Editor Customizer

    You would need to create a custom function to hook the audio file to the head of your site. Then, you would use a conditional statement to make sure it is only called on your home page.

    WordPress Conditionals can be found here:
    http://codex.wordpress.org/Conditional_Tags

    You would want to use the if (is_home()) { conditional.

    Sorry about the long delay between replies. iv’e been working on some music for school.

    I suck at php coding and barely know how to do this. I tried searching for a plugin for this but with no luck. Does anyone here know of a plugin that will edit the php and stuff for me so I don’t have to?

    thanks.

    Josh

    (@josh401)

    Moderator and Editor Customizer

    Something like this should work:

    <?php
    if (is_home()) {
    	function add_audio_homepage() {
    		?><embed height="50px" width="100px" src="PATH_TO_SONG.mp3" /><?php
    	}
    	add_action('wp_head', 'add_audio_homepage');
    }
    ?>

    Add that preferably to your child themes functions.php file. Or, you can add it to the bottom of your main themes functions.php file, but it will be deleted whenever you update your theme.

    NOTE: You will need to change the source path in the code I gave you to reflect the location of your .mp3 file. You can use an absolute path.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘embeding audio only in the homepage’ is closed to new replies.