Basic plugin development help
-
Hi there,
I’m new to wordpress development (obviously) and am having issues trying to get a very simple plugin up and running. The idea is that it takes a url from an anchor and adds images to particular file types:
<? /* Plugin Name: Add Document Type Styles Plugin URI: http://robospeare.com/wordpress/plugin_doctypes Description: Detects URLs in your post and page contet and applies style to those that link to documents so as to identify the document type. Support for .pdf and .mp3 Version: 1.0 Author: Oliver Sneyd Author URI: http://robospeare.com */ function documenttypestyles_regex( $text ) { $text = ereg_replace( 'href=([\'|"][:alnum:]|[:punct:]]*) \.(pdf|mp3) ([\'|"])', 'herf=\\1.\\2\\3 class="link \\2"', $text); return $text; } function documenttypestyles_styles() { echo "<style>"; echo ".link { background-repeat : no-repeat; padding : 2px 0 2px 20px; }\n"; echo ".pdf { background-image: url('" . WP_PLUGIN_URL . "/documenttypestyles/pdfIcon.jpg'); }\n"; echo ".mp3 { background-image: url('" . WP_PLUGIN_URL . "/documenttypestyles/mp3Icon.gif'); }\n"; echo "</style>\n\n"; } add_filter( 'the_content', 'documenttypestyles_regex' ); add_action( 'wp_head', 'documenttypestyles_styles' ); ?>
But if I have anything in the documenttypestyles_styles function the header for every page gets messed up – this is displayed at the top of every page:
“; echo “.link { background-repeat : no-repeat; padding : 2px 0 2px 20px; }\n”; echo “.pdf { background-image: url(‘” . WP_PLUGIN_URL . “/documenttypestyles/pdfIcon.jpg’); }\n”; echo “.mp3 { background-image: url(‘” . WP_PLUGIN_URL . “/documenttypestyles/mp3Icon.gif’); }\n”; echo “\n\n”; } add_action( ‘wp_head’, ‘documenttypestyles_styles’ ); ?>
Any ideas what I’m doing wrong here?
- The topic ‘Basic plugin development help’ is closed to new replies.