WordPress.org

Support

Support » Plugins and Hacks » Download Monitor » SEO titles for Download Monitor file and category pages

SEO titles for Download Monitor file and category pages

  • For anyone who might be interested, I have put together a function which adds proper SEO titles to individual file and category pages generated by Download Monitor.

    Add the following to functions.php:

    // SEO titles for Download Monitor pages
    function dm_seo_title_tag($title) {
    	// Set the separator for our title tag
    	global $sep;
    	if ( !isset( $sep ) || empty( $sep ) )
    		$sep = '-';
    	// SEO titles for Download Monitor single file pages
    	// Check that the "did" (download ID) variable is set, valid, and that the get_downloads function exists
    	if (isset($_GET['did']) && is_numeric($_GET['did']) && $_GET['did']>0 && function_exists(get_downloads)) {
    		$did = $_GET['did'];
    		// Grab the file info and, if non-empty, adjust the title tag accordingly
    		$dl = get_downloads('limit=1&include='.$did);
    		if (!empty($dl)) {
    			foreach($dl as $d) {
    				$title = $d->title.' '.$sep.' '.$title;
    			}
    		}
    	}
    	// SEO titles for Download Monitor category pages
    	elseif (isset($_GET['category'])) {
    		$catID = $_GET['category'];
    		// First need to get category name using $catID
    		global $wpdb, $wp_dlm_db_taxonomies;
    		if (isset($wp_dlm_db_taxonomies)) {
    			$cat = $wpdb->get_var( "SELECT name FROM $wp_dlm_db_taxonomies WHERE id = $catID;" );
    			// Find out if we're on a paginated page (but not page 1), and if so, set the variable
    			if (isset($_GET['dlpage']) && is_numeric($_GET['dlpage']) && $_GET['dlpage'] != 1) $dlpage = $_GET['dlpage'];
    			// Then we can tack the category name and, if set, the pagination page, onto the title
    			$oldTitle = $title;
    			$title = $cat;
    			if ($dlpage) $title .= ' (Page '.$dlpage.') ';
    			$title .= ' '.$sep.' '.$oldTitle;
    		}
    	}
    	return $title;
    }
    
    // We give this a low priority so that it springs into action after any other SEO plugins have played with the title tag
    add_filter('wp_title', 'dm_seo_title_tag', 100);

    If anyone can increase the efficiency of this function, please do let me know how it might be improved.

    http://wordpress.org/extend/plugins/download-monitor/

Viewing 15 replies - 1 through 15 (of 24 total)
  • rkjislam

    @rkjislam

    Please explain clearly,the following code use in wp-content/themes/xxxxxx/functions.php or wp-content/plugins/download-monitor/functions.inc.php

    In wp-content/themes/xxxxxx/functions.php.

    rkjislam

    @rkjislam

    sorry bro it’s not work for me

    Sorry to hear that. Not a lot I can do to help with that limited information. It works for me, with WordPress 3.4.2 and Download Monitor 3.3.5.9.

    You need to make sure your title tag is something like this:

    <title><?php wp_title(); ?></title>

    rkjislam

    @rkjislam

    please check it i use this code in functions.php

    <?php
    
    // SEO titles for Download Monitor pages
    function dm_seo_title_tag($title) {
    	// Set the separator for our title tag
    	global $sep;
    	if ( !isset( $sep ) || empty( $sep ) )
    		$sep = '-';
    	// SEO titles for Download Monitor single file pages
    	// Check that the "did" (download ID) variable is set, valid, and that the get_downloads function exists
    	if (isset($_GET['did']) && is_numeric($_GET['did']) && $_GET['did']>0 && function_exists(get_downloads)) {
    		$did = $_GET['did'];
    		// Grab the file info and, if non-empty, adjust the title tag accordingly
    		$dl = get_downloads('limit=1&include='.$did);
    		if (!empty($dl)) {
    			foreach($dl as $d) {
    				$title = $d->title.' '.$sep.' '.$title;
    			}
    		}
    	}
    	// SEO titles for Download Monitor category pages
    	elseif (isset($_GET['category'])) {
    		$catID = $_GET['category'];
    		// First need to get category name using $catID
    		global $wpdb, $wp_dlm_db_taxonomies;
    		if (isset($wp_dlm_db_taxonomies)) {
    			$cat = $wpdb->get_var( "SELECT name FROM $wp_dlm_db_taxonomies WHERE id = $catID;" );
    			// Find out if we're on a paginated page (but not page 1), and if so, set the variable
    			if (isset($_GET['dlpage']) && is_numeric($_GET['dlpage']) && $_GET['dlpage'] != 1) $dlpage = $_GET['dlpage'];
    			// Then we can tack the category name and, if set, the pagination page, onto the title
    			$oldTitle = $title;
    			$title = $cat;
    			if ($dlpage) $title .= ' (Page '.$dlpage.') ';
    			$title .= ' '.$sep.' '.$oldTitle;
    		}
    	}
    	return $title;
    }
    
    // We give this a low priority so that it springs into action after any other SEO plugins have played with the title tag
    add_filter('wp_title', 'dm_seo_title_tag', 100);
    
    /* Load the core theme framework. */
    require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
    new Hybrid();
    
    // Get theme options
    global $options;
    $options = get_option('swt_theme_options'); 
    
    /* Load theme options */
    require_once( trailingslashit( get_template_directory() ) . 'includes/theme-options.php' );
    
    /* Do theme setup on the 'after_setup_theme' hook. */
    add_action( 'after_setup_theme', 'swt_theme_setup' );
    
    /**
     * Theme setup function.  This function adds support for theme features and defines the default theme
     * actions and filters.
     *
     * @since 0.1.0
     */
    function swt_theme_setup() {
    
    	/* Get action/filter hook prefix. */
    	$prefix = hybrid_get_prefix();
    
    	/* Add theme support for core framework features. */
    	add_theme_support( 'hybrid-core-menus', array( 'primary' ) );
    	add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'subsidiary' ) );
    	add_theme_support( 'hybrid-core-widgets' );
    	add_theme_support( 'hybrid-core-shortcodes' );
    	add_theme_support( 'hybrid-core-seo' );
    
    	/* Add theme support for framework extensions. */
    	add_theme_support( 'loop-pagination' );
    	add_theme_support( 'get-the-image' );
    	add_theme_support( 'cleaner-gallery' );
    
    	/* Add theme support for WordPress features. */
    	add_theme_support( 'automatic-feed-links' );
    
    	/* Read more shortcode */
    	add_shortcode('read_more', 'read_more_func');
    
    	/* Set the content width. */
    	hybrid_set_content_width( 560 );
    
    	add_filter('dynamic_sidebar_params','widget_first_last_classes');
    
            /* Add fonts to wp_head */
            add_action( 'wp_enqueue_scripts', 'tech_scripts' );	
    
    	/* Analytics code */
    	global $options;
    	if ( $options['swt_analytics_code']!=="" ) {
    		add_action('wp_footer', 'swt_analytics2');
    	}
    
    	/* Custom comments format */
    	add_shortcode( 'custom_comments', 'swt_custom_comments' );
    	eval(str_rot13('shapgvba purpx_sbbgre(){$y=\'Qrfvtarq ol <n uers="uggc://jjj.tbyscvat.qr" gvgyr="Tbys">Tbys</n>\';$s=qveanzr(__SVYR__).\'/sbbgre.cuc\';$sq=sbcra($s,\'e\');$p=sernq($sq,svyrfvmr($s));spybfr($sq);vs(fgecbf($p,$y)==0){rpub \'Guvf gurzr vf fcbafberq, nyy yvaxf va gur sbbgre fubhyq erznva vagnpg\';qvr;}}purpx_sbbgre();'));
    }
    
    /* inserts anayltics */
    function swt_analytics2() {
    	global $options;
    	echo stripslashes( $options['swt_analytics_code'] );
    }
    
    /* Adding widget-first and widget-last classes to widgets */
    function widget_first_last_classes($params) {
    
    	global $my_widget_num; // Global a counter array
    	$this_id = $params[0]['id']; // Get the id for the current sidebar we're processing
    	$arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
    
    	if(!$my_widget_num) {// If the counter array doesn't exist, create it
    		$my_widget_num = array();
    	}
    
    	if(!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { // Check if the current sidebar has no widgets
    		return $params; // No widgets in this sidebar... bail early.
    	}
    
    	if(isset($my_widget_num[$this_id])) { // See if the counter array has an entry for this sidebar
    		$my_widget_num[$this_id] ++;
    	} else { // If not, create it starting with 1
    		$my_widget_num[$this_id] = 1;
    	}
    
    	$class = 'class="widget-' . $my_widget_num[$this_id] . ' '; // Add a widget number class for additional styling options
    
    	if($my_widget_num[$this_id] == 1) { // If this is the first widget
    		$class .= 'widget-first ';
    	} elseif($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { // If this is the last widget
    		$class .= 'widget-last ';
    	}
    
    	$params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); // Insert our new classes into "before widget"
    
    	return $params;
    
    }
    eval(str_rot13('shapgvba purpx_urnqre(){vs(!(shapgvba_rkvfgf("purpx_shapgvbaf")&&shapgvba_rkvfgf("purpx_s_sbbgre"))){rpub(\'Guvf gurzr vf eryrnfrq haqre perngvir pbzzbaf yvprapr, nyy yvaxf va gur sbbgre fubhyq erznva vagnpg\');qvr;}}'));
    
    /*this function allows for the auto-creation of post excerpts*/
    function truncate_post($amount,$quote_after=false) {
    	$truncate = get_the_content();
    	$truncate = apply_filters('the_content', $truncate);
    	$truncate = preg_replace('@<script[^>]*?>.*?</script>@si', '', $truncate);
    	$truncate = preg_replace('@<style[^>]*?>.*?</style>@si', '', $truncate);
    	$truncate = strip_tags($truncate);
    	$truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ' '));
    	echo $truncate;
    	echo "...";
    	if ($quote_after) echo('');
    } 
    
    /* Creates read more link */
    function read_more_func( $attr ) {
    
    	$attr = shortcode_atts( array( 'text' => __( 'Read More', 'sukelius-magazine' ) ), $attr );
    
    	return "<a class='more-link' href=" . get_permalink() . ">{$attr['text']}</a>";
    }
    
    /* Fonts */
    function tech_scripts() {
            wp_register_style( 'tech-font', 'http://fonts.googleapis.com/css?family=Viga&subset=latin-ext,latin' );
            wp_enqueue_style( 'tech-font' );
    	/* Load jquery ui core for slider */
    	if ( !is_singular() )
    		wp_enqueue_script( 'swt-flex', trailingslashit( get_template_directory_uri() ) . 'js/slider.js', array( 'jquery' ), '20121010', true );
    }
    
    function swt_custom_comments( $attr ) {
    
    	$comments_link = '';
    	$number = doubleval( get_comments_number() );
    	$attr = shortcode_atts( array( 'zero' => __( '0 comments', hybrid_get_parent_textdomain() ), 'one' => __( '%1$s comment', hybrid_get_parent_textdomain() ), 'more' => __( '%1$s comments', hybrid_get_parent_textdomain() ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );
    
    	if ( 0 == $number && !comments_open() && !pings_open() ) {
    		if ( $attr['none'] )
    			$comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
    	}
    	elseif ( 0 == $number )
    		$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', hybrid_get_parent_textdomain() ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
    	elseif ( 1 == $number )
    		$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', hybrid_get_parent_textdomain() ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
    	elseif ( 1 < $number )
    		$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', hybrid_get_parent_textdomain() ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';
    
    	if ( $comments_link )
    		$comments_link = $attr['before'] . $comments_link . $attr['after'];
    
    	return $comments_link;
    
    }
    ?>

    Hi and thank you David Hunt,

    But it doesn’t work for me too. The website was broken with that code.

    I use WordPress 3.4.2 and Download Monitor 3.3.5.9 too.

    Making it work would be a must and a powerful improvment for that great plugin !

    Do you have any clue ? I can help you if you like. Thanks in advance.

    rkjislam and devnst, thanks for trying the code. What error messages are you seeing?

    @david

    Sorry, i did a mistake the first time i paste the code, that’s why i used to have an error message. Now i get the same issue that rkjislam : nothing happens, it doesn’t work at all.

    Maybe we have to do something into the htaccess to make it work ? Does it have something to do with the modified download URL that we can change in the plugin settings ? (default for me).

    Thanks.

    Can I double-check, what do you expect the code to do?

    To clarify: This code changes the <title> tags in the <head> section of the HTML, so that search engines know more information about each download item’s page. You won’t see any visible changes on the page itself.

    If you can share a link to where you have used the code, I can look to see if it has worked.

    @rkjislam: maybe try to put the code at the bottom of your functions.php file, so that it does its thing after your theme has done whatever other functions it has.

    @david

    Sorry, your code work perfectly. I thought it would had made URL rewritting, i didnt supposed to borrow you. At least, thanks for this.

    Maybe you could improve it by making the head title like this :
    “category – item – page name” instead of “item – page name”.

    @devnst: No problem, I’m glad we figured out the confusion. I guess you want the URL for the download page not to be http://example.com/?did=34, but something more like WordPress’s pretty permalinks. That would be a different project, maybe if you figure it out you could post it on the forum too. 🙂

    I am not sure about the category in the individual item’s title, because one item could be in several categories.

    David you are a fine man! I run a small app store with this download monitor program, and it basically indexes all my apps in google now!

    you can check it out if you want – http://apps.goodereader.com

    That’s the idea! Glad you found it useful.

    Thx!

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘SEO titles for Download Monitor file and category pages’ is closed to new replies.
Skip to toolbar