WordPress.org

Ready to get started?Download WordPress

Forums

Download Monitor
SEO titles for Download Monitor file and category pages (25 posts)

  1. David Hunt
    Member
    Posted 1 year ago #

    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/

  2. rkjislam
    Member
    Posted 1 year ago #

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

  3. David Hunt
    Member
    Posted 1 year ago #

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

  4. rkjislam
    Member
    Posted 1 year ago #

    sorry bro it's not work for me

  5. David Hunt
    Member
    Posted 1 year ago #

    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>

  6. rkjislam
    Member
    Posted 1 year ago #

    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;
    
    }
    ?>
  7. devnst
    Member
    Posted 1 year ago #

    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.

  8. David Hunt
    Member
    Posted 1 year ago #

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

  9. devnst
    Member
    Posted 1 year ago #

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

  10. David Hunt
    Member
    Posted 1 year ago #

    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.

  11. David Hunt
    Member
    Posted 1 year ago #

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

  12. devnst
    Member
    Posted 1 year ago #

    @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".

  13. David Hunt
    Member
    Posted 1 year ago #

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

  14. goodereader
    Member
    Posted 1 year ago #

    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

  15. David Hunt
    Member
    Posted 1 year ago #

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

  16. colingreig
    Member
    Posted 1 year ago #

    Thx!

  17. goodereader
    Member
    Posted 1 year ago #

    This works great for titles, but is there anyways to makes sure the description in the download is indexed? I have around 16,000 apps on my site, and just the title is being indexed and not the description, this is creating thousands of duped descriptions. Is there anyway we can get google to index the description of the download?

    for example this http://apps.goodereader.com/playbook/new-blackberry-playbook-apps/?did=14583

  18. David Hunt
    Member
    Posted 1 year ago #

    Hi Goodereader!

    I did create a similar function for meta descriptions, but it relies on the WordPress SEO plugin by Yoast. If you don't already use that plugin, I can highly recommend it.

    Here's my function:

    function dvd3141_downloadmonitor_metadesc($metadesc){
    	// SEO meta descriptions for individual Download items
    	if (isset($_GET['did']) && is_numeric($_GET['did']) && $_GET['did']>0 && function_exists(get_downloads)) {
    		$did = $_GET['did'];
    		$dl = get_downloads('limit=1&include='.$did);
    		if (!empty($dl)) {
    			foreach($dl as $d) {
    				$metadesc = __('Download: ','namespace').$d->title;
    			}
    		}
    	}
    	// SEO meta descriptions for Download taxonomy 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 use the category name and, if set, the pagination page, in the meta description
    			$metadesc = __('Downloads in the category of: ', 'namespace').$cat;
    			if ($dlpage) $metadesc .= ' (Page '.$dlpage.')';
    		}
    	}
    	return $metadesc;
    }
    
    add_filter( 'wpseo_metadesc', 'dvd3141_downloadmonitor_metadesc');

    As you can see, my function still uses the download's title in the meta description, but you could feasibly replace that with the download's description, although you should probably truncate it.

    Hope that has provided a useful starting point for you.

    Best,

    David

  19. goodereader
    Member
    Posted 1 year ago #

    hey david, this script is of course put in function.php right? will it disrupt the current script that was posted on the top for title seo?

  20. David Hunt
    Member
    Posted 1 year ago #

    Yup, in functions.php, and it doesn't affect the other script.

  21. goodereader
    Member
    Posted 1 year ago #

    i cant get that one plugin to work on my app store, i can get all in one Seo though, would that script work with it? Thats the more popular one than the one done by yoast.

  22. David Hunt
    Member
    Posted 1 year ago #

    Sorry, I use Yoast's plugin. I've never used All in One SEO, so I've no idea if this script could be used for that plugin.

  23. goodereader
    Member
    Posted 1 year ago #

    Hey David! Did you have to do anything special in Yoast, or to enable a specific setting for this to work? I managed to get the plugin working, but descriptions don't seem to be getting indexed properly.

  24. David Hunt
    Member
    Posted 1 year ago #

    I looked at a sample page on your site and, from the source, can see the the meta description appears twice in the <head> section:

    <meta name="description" content="[download_page pop_count="333" exclude_cat="1,2,3,4,5,48,51,52,107,236,190,268,269,270,271,272,325,266,426,427,428,429,430,444,445,446,447,448,449,450" />

    and then

    <meta name="description" content="Download: Photo Grid - Collage Maker for BB10"/>

    The second one is the output of my code -- I am not sure where the first one comes from, maybe from the theme you are using. But clearly you shouldn't have two descriptions in your header, so you'll need to investigate what is producing that first description, and disable it.

    Hope that helps.

    David

  25. goodereader
    Member
    Posted 1 year ago #

    I think Yoast SEO plugin was duplicating my header content, would you be willing to look at my functions.php plugin and see if you can fix it up, i think mines whack.

    I know i am using the code you posted at the very top of the article, for the Title SEO, to generate titles for all my apps, and then i used the secondary code you mentioned only worked in yoast.

    if you can, drop me a line with my websites contact form, and ill send it over, even be willing to compensate you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags