Title: Combine 2 codes
Last modified: August 19, 2016

---

# Combine 2 codes

 *  Resolved [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * (@tim_gassel)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/combine-2-codes/)
 * Hi,
 * Is it possible to combine these codes?
 * `<?php echo do_shortcode('[wp-blogroll catname="XXX"]'); ?>`
 * `<?php the_title(); ?>`
 * I want to replace XXX with the_title.
 * Thanks,
 * Tim

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1665883)
 * [http://codex.wordpress.org/Function_Reference/the_title](http://codex.wordpress.org/Function_Reference/the_title)
 * to get the title as a string to use in php, use
 * `the_title('','',false)` inplace of “XXX”
 * (if that will work might depend on the location you are using it in)
 * there might also be the possibility of adding `global $post;’
    and then use `
   $post->post_title` inplace of “XXX”
 *  Thread Starter [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * (@tim_gassel)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666267)
 * Thanks for you answer!
 * Unfortunately I can not make it work.
    I can’t program very well…
 * I would be very grateful if someone can explain a little bit more?
 * I use the code outside the loop.
 * Thanks again!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666268)
 * have you tried something like:
 *     ```
       <?php global $post;
       $title = $post->post_title;
       echo do_shortcode('[wp-blogroll catname=$title]'); ?>
       ```
   
 * (untested)
 * is ‘the_title()’ the title of a page or post?
    and where do you try to run this
   code? header? sidebar?
 *  Thread Starter [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * (@tim_gassel)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666269)
 * Thanks,
 * I tried the code, it doesn’t work.
 * the_title() is the title of a page.
    I tried to run this code in my sidebar.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666270)
 * it may need a ‘wp_reset_query();’ at the start of the code, to reset any distortions
   of the query_string through the main content.
    also added a test line to see 
   the content of $title, to check if it got the right title:
 *     ```
       <?php wp_reset_query();
       global $post;
       $title = $post->post_title;
       echo $title; //for testing only, remove later
       echo do_shortcode('[wp-blogroll catname=$title]'); ?>
       ```
   
 * (today is _national wp-reset-query day _; lol 😉
 * another test:
    add the title of the page manually into the variable, to check
   if the shortcode call works with a variable:
 *     ```
       <?php global $post;
       $title = 'Title of the Page';
       echo do_shortcode('[wp-blogroll catname=$title]'); ?>
       ```
   
 *  Thread Starter [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * (@tim_gassel)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666271)
 * I tested both codes, but they didn’t work.
    The echo $title; test worked well,
   my title showed up. But in the string of the do_shortcode it still doesn’t work.
 * I also tried to put my title manually in the variable. still with no result.
 * Sorry I’m so difficult…
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666272)
 * another try (i just realized that the `do_shortcode()` function is expecting 
   a string, which my earlier suggestion does not deliver)
 *     ```
       <?php wp_reset_query();
       global $post;
       $title = $post->post_title;
       echo $title; //for testing only, remove later
       echo do_shortcode('[wp-blogroll catname="' . $title . '"]'); ?>
       ```
   
 * if that fails:
    is the short code self-made or from a plugin? if plugin, can 
   you post the download link of the plugin? if self-made, could you paste the code
   into a [http://wordpress.pastebin.com/](http://wordpress.pastebin.com/) and post
   the link to it here?
 *  Thread Starter [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * (@tim_gassel)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666273)
 * Yeah! The last code you gave worked.
 * Thank you very much for this sulution.
    You saved my day.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Combine 2 codes’ is closed to new replies.

 * 8 replies
 * 2 participants
 * Last reply from: [Tim_gassel](https://wordpress.org/support/users/tim_gassel/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/combine-2-codes/#post-1666273)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
