WordPress.org

Ready to get started?Download WordPress

Forums

embeding audio only in the homepage (4 posts)

  1. marrie125
    Member
    Posted 2 years ago #

    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.

  2. 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.

  3. marrie125
    Member
    Posted 2 years ago #

    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.

  4. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic